Query options if variable not set

  • Hello i have a query that i need help with.

    The query has a filter

    "where month= @month and customer = @customerr"

    If i do not set the customer i need to get all the records of the month.

    I know i can do an if and write the 2 queries, but i want to know if there is an option to avoid the "if"

    Thank you

  • I'd go with the IF statement.

    Otherwise, you might run in to a catch-all[/url] scenario.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • If you go with an IF, watch out for this:

    http://sqlinthewild.co.za/index.php/2009/09/15/multiple-execution-paths/

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

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

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