I want to be able to pass in a list of parameters, and ignore the ones which are NULL. So that the query is in effect pretending that the filter isn't there and ignoring it.
I was doing it like this:
(@thing IS NULL or Thing=@thing)
Is this right, and if so, would it perform badly? It's seems to be a lot slower than constructing the SQL separately.
What's the optimal way to do this?
FIXED! See Marc Gravell's answer. In summary using IS NULL many times is a big performance hit.