September 25, 2013 at 10:59 am
hi, idk if I'll give to explain very well.
but I need to make a query with the following conditions
example:
I have three fields are the parameters for my query
the fact is that when one of the parameters not leave blank or empty I need you always return the information and if not that if I put the three fields always return the information.
thnk
September 25, 2013 at 12:43 pm
Your question is not entirely clear.
Can you post some sample data and desired output?
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
September 26, 2013 at 8:04 am
I agree with Koen - it's hard to understand what you want.
However, I'm willing to make a guess that it's about how to write the WHERE clause of your querysomething like this, if your three parameters are called @F1, @F2, and @F3
select <list of things to be selected>
from <data source - be it a single table of some joins>
where (Field1 = @F1 or @F1 = '' or @F1 is null)
and
(Field2 = @F2 or @F2 ='' or @F2 is null)
and
(Field3 = @F3 or @F3 ='' or @F3 is null)
However, as you original question is not clear, that may well be wrong; maybe the where clause should be
where (Feild1 = @F1 and Field2 = @F2 and Field3 = @F2)
or @F1 is null or @F2 is null or @F3 is null
or @F1 = '' or @F2 = '' or @F3 = ''
Or maybe the = '' tests are not needed and could cause an error because the three parameters are of a type where that test makes no sense, and the three parameters are handed in as parameters to a stored procedure so if left blank they tuen up as null (which of course just means "not present").
Or maybe none of that is what you want - as Koen said, your question is not clear.
Tom
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply