Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Multiple where statements
Message
De
18/02/2005 11:04:09
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Divers
Thread ID:
00988288
Message ID:
00988356
Vues:
30
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?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform