Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Ms sql s.p.
Message
 
À
28/09/2007 05:49:15
Issam Mansour
Jordan Business Machines
Amman, Jordanie
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01257381
Message ID:
01257387
Vues:
15
>Hi,
>
>is there any other way to build the following condition on S.P.
>if @catcode <> ''
>begin
>select * from item where catcode = @catcode
>end
>
>if @catcode <> '' and @subcode <> ''
>begin
>select * from item where catcode = @catcode and subcode = @subcode
>end
>
>if @catcode = '' and @subcode <> ''
>begin
>select * from item where subcode = @subcode
>end
>
>best Regards

Try:
IF @catcode <> '' OR @subcode <> '' -- at least one of them is not empty
   BEGIN
       SELECT * FROM Item
              WHERE (@catcode = '' OR  catcode = @catcode) AND
                    (@subcode = '' OR  subcode = @subcode)
   END
If you want ALL records if both variables are empty, just remove IF statement.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform