My advice:INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

Gail, this isn't a catch-all query. According your article, a catch-all query is one "where the user may enter any one (or more) of a number of optional parameters". Here, the clearly stated requirement is different: "I allways submit all 4 input values". Those four values must, therefore, always be tested for - I don't see any other way to fulfil the requirement than the basic structure the OP ended up with in his final post.

John Mitchell-245523 (9/2/2014)Gail, this isn't a catch-all query. According your article, a catch-all query is one "where the user may enter any one (or more) of a number of optional parameters". Here, the clearly stated requirement is different: "I allways submit all 4 input values". Those four values must, therefore, always be tested for - I don't see any other way to fulfil the requirement than the basic structure the OP ended up with in his final post.

John

I've written quite a few dynamic search stored procedures, with my thanks out to Gail and her SQL-in-the-Wild article for showing me the way.

I always allow for the case of submitting all parameters. It is just that oftentimes, some (or many) of them are NULL. And it appears that this could be the case for this OP, given his attempts to handle NULLs in the example he provided.

This is a case where I at least (and probably Gail too) are attempting to shift the OP's paradigm.

My advice:INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

It could also work, the way you describe, where i only submit either of the 4 values or all 4, in some cases.

Didn´t know,that my statement 'I always submit all 4 values', had such a big impact in the way, the SP is constructed. Actually I thought everything would easier, if all 4 values were always submitted.