For practical purposes, it usually doesn’t matter too much whether you use ‘that’ or ‘which’ – sometimes one or the other will simply sound better in a sentence. Nevertheless, in some situations the choice of ‘that’ and ‘which’ leads to subtly different outcomes. For example:
(1) Brian asked Gloria to pass the book that was on the chair.
(2) Brian asked Gloria to pass the book which was on the chair.
If you add a comma to the sentence above (in the only feasible spot), it becomes:
(3) Brian asked Gloria to pass the book, which was on the chair.
In (1) and (2), the meaning is effectively the same – Brian wants a specific book, the one that was on the chair (but possibly isn’t any more). In (3) the book is not identified specifically as the book that was on the chair; Brian asked Gloria for the book and she found it on the chair. But try replacing ‘which’ in (3) with ‘that’; it doesn’t work (why is, at least for me, one of those visceral grammar rules).
In general, choose ‘that’ when the idea you’re trying to convey is crucial to the meaning of the sentence. In (3) above, if the words following the comma were deleted the sentence would still make sense (Brian asked Gloria to pass the book). Choose ‘which’ to add extra, non-essential information to a sentence.