Query in SP with none or (one or more) filter

  • I need to create a SP which will filter based on none, one or more criteria user selects. I idea is give the user to select, say, customers based on City, Territory, Region, Town etc (there are around 10 filters to selected). The user may or may not select any filters.

    What would be the best way to build a query for this purpose. I am currently trying with a CASE inside the WHERE clause but so far not working. Also, I am clueless on placing "AND" keyword when building conditions.

    Please help

  • The dynamic SQL will probably be the best. See Gail's blog:

    http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/

    --Vadim R.

  • Thank you for guiding me to the right direction.

    Did it successfully using dynamicSQL and it works like a charm.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply