You need to look at the structure of your sentence to help you decide whether to use which or that.
Does the word you need introduce a piece of information that is NOT essential in the sentence? In other words, if you removed the text that followed it, would the remainder of the sentence still have the same meaning? If so, use ‘…, which…’. Notice the comma. It breaks the sentence at the point where this additional information is being added.
Here is an example: 'The dog, which had a brown coat, was loved by everyone.’
The main point of this sentence is to tell you the dog was loved by everyone. The fact that it had a brown coat is an additional piece of information that is not essential. The information could be removed from the sentence and you would still know the dog was loved by everyone.
On the other hand, what if the word you need introduces a piece of information that is essential in the sentence? In other words, if you removed this piece of the text, the sentence would be missing an important piece of information. If this is the case, use ‘… that …’. (Notice there is no comma.)
Here is an example: ‘The dog that had a brown coat was loved by everyone.’
This sentence tells you there were a few dogs, but only the one with a brown coat was loved by everyone. If you left out the text about the brown coat, you would not have the important information telling you how to identify the dog everyone loved.