Dynamic WHERE statement

  • Thread starter Thread starter Jim Warren
  • Start date Start date
J

Jim Warren

If I pass a variable to @Cost_Center that is 'SMS', 'SMP' OR 'ALL'
'ALL' will return records that have either 'SMS' or 'SMP' in them.
Now I am using an if statement that has the entire SQL statement in the body
of the
conditional.

I tried this

Where

IF (@Cost_Center = 'All')

Begin

code...
and i.cost_center in ('SMS','SMP')

End

ELSE

Begin

code...
and i.cost_center = @Cost_Center

End


Thanks
Jim
 
In case you haven't figured it out, this is a "windows XP setup and
deployment group" and not a "how to code SQL2k group". Your best bet is to
repost in one of the many SQL newsgroups for the "gurus" there to answer
your question. ;-)
 
Back
Top