June 20, 2014 at 9:00 pm
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.
June 20, 2014 at 9:31 pm
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/
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
June 21, 2014 at 8:36 pm
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