Seacrh Criteria Parameter Value

  • Say I have a query like

    DECLARE @ID UNIQUEIDENTIFIER, @SOMEDATE DATE

    SELECT * FROM myTable WHERE ID = @ID AND DATEFIELD=@SOMEDATE

    I want to pass values to @ID and @SOMEDATE, such that it meets the WHERE criteria for all values in the respective fields.

    What parameter value should I pass such that all values are selected?

    In the actual SP, I have uniqueidentifier, varchar and date parameters.

  • To clarify, you're looking for a catch-all query?

    Something like:

    WHERE ( ID = @ID or @ID IS NULL) AND (Somedate = @SomeDate OR @SomeDate IS NULL)

    If so, look here:

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


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • Thanks! That was what I was looking for! I was not aware of catch-all queries previously.

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

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