In the dataset of a report in the Reporting Services 2000, I need to write an SQL statment with a Where condition which makes all possible combination of 10 conditions.
Could that be done by any way except by ORing and ANDing all the conditions?
For example, If I have three conditions, A, B, and C, I need all possible combinations in a WHERE condition as follows
SELECT *
FROM table
WHERE A = @.A
OR B = @.B
OR C = @.C
OR A = @.A and B = @.B
OR A = @.A and C = @.C
OR B = @.B and C = @.C
OR A = @.A and B = @.B and C = @.C
Note: @.A, @.B, @.C are Report parameters
I need to do the same with 10 conditions, I think it's too much to do it that way.
My question is, is there any other way I can do that with the parameters of a Report in Reporting Services.
Any help is greatly appreciated.
Thank you.SELECT * FROM table t1 CROSS JOIN table t2
?|||How you write it your where clause will be true if any of A = @.A, B = @.B or C = @.C evaluates to true.
SELECT *
FROM table
WHERE A = @.A OR B = @.B OR C = @.C
Will be true for all combinations like (A + @.A and B = @.B) because first statement say that if only 1 is ok it will be true.
|||If it is a stored procedure, pass in -1 or '-1' for All values.
IF @.A = -1 SET @.A = null
IF @.B...
IF @.C...
SELECT *
FROM table
WHERE COALESCE(@.A,A) = A
AND COALESCE(@.B,B) = B
AND COALESCE(@.C,C) = C
COALESCE substitutes null values with the value specified as the second parameter. So A will always = A when @.A = null.
Maybe this will help?
No comments:
Post a Comment