Hi Rit,
You may have figured it out by now, but my solution does exactly what you want. The 1 in the param value is used to remove the impact of the WHERE clause entirely:
Consider my original WHERE clause:
Code:
WHERE SomeField = @someParam OR @someParam = 1
Let's say @someParam equals 4. Then the WHERE clause will be:
Code:
WHERE SomeField = 4 OR 4 = 1
This returns all records that have the value 4 in the SomeField column. Only the part before the OR has effect, because 4 does not equal 1.
However, if @someParam itself (the
value of the parameter) equals 1, the where clause looks like this:
Code:
WHERE SomeField = 1 OR 1 = 1
The OR 1 = 1 is important here. Since 1 always equals 1, the second part (after the OR statement) always returns true, effectively removing the WHERE restrictions all together.
In a more complex WHERE clause, you may need to add additional parentheses to block this additional option from removing the effect of the entire WHERE clause.
HtH,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.