Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Ms sql s.p.
Message
From
28/09/2007 06:59:41
 
 
To
28/09/2007 05:49:15
Issam Mansour
Jordan Business Machines
Amman, Jordan
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01257381
Message ID:
01257387
Views:
17
>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.
Previous
Reply
Map
View

Click here to load this message in the networking platform