Posted by Ryan on 11/17/05 04:36
I am trying to create a stored procedure whose where clause is
dependent on a parameter.
If the parameter @myparam is null or '' then I want the where clause to
be one thing, else I want it to be a completely different thing. I can
do it easily using iif but obviously that is not an option here...
Here is what I have:
Select @ FROM my table WHERE
IF @myparam = '' or @myparam is null
[MyField] = like '%'
ELSE
charindex(@myparam,[MyField]) > 0)
I have also tried variations of this and tried it using CASE. I keep
getting syntax errors. Do I have to write multiple SELECT statements
for every possibility. If I can get this working the query will
actually be a bit more complex, although it will follow this basic
structure...in other words, I'd rather not have to write multiple
queries when the only thing that is changing is the WHERE portion...
Thanks!
Ryan
[Back to original message]
|