Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Multiple where statements
Message
From
18/02/2005 11:04:09
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
00988288
Message ID:
00988356
Views:
28
WOW!
That was clean and beautiful!
Thanks Sergey

>Try
>SELECT *
>  FROM vw.foo  f
>  WHERE f.cost_center LIKE
>    CASE WHEN @cost_center = 'ALL' THEN '%' ELSE @cost_center END
>
>
>>After two years I am back doing SQL Server, I don't mind.
>>
>>
>>My first asignment is to create a report for one of the cost centers or two of the cost centers depending on if 'ALL','SMS', or 'SMP' is inputed by the user.
>>
>>I made a view with just 'SMS' and 'SMP' in it.
>>
>>What is the best way to handle this, I have been using brute force i.e.
>>
>>
>>if @cost_center = 'ALL'
>>
>>Begin
>>SELECT *
>>FROM vw.foo f
>>END
>>
>>ELSE
>>
>>BEGIN
>>
>>SELECT *
>>FROM vw.foo f
>>WHERE f.cost_center = @cost_center
>>
>>END
>>
>>Is there a better way?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform