• 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 mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    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.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St