How to use Case Statement  
Author Message
FRSNK





PostPosted: Fri Jun 16 18:41:51 CDT 2006 Top

SQL Server Developer >> How to use Case Statement

I tried and came up with no solution.
I need to use Stored procedure and no dynamic sql.
I ma using ms sql 2000 service pack 3

I am using three different tables. How I can make it to run union statements
only for those table where passing values for the variable is 1

Thanks
Tanweer










select id, code form people_list
union
select id, code form Client_list
union
select id, code form joborder_list

SQL Server152  
 
 
Roy





PostPosted: Fri Jun 16 18:41:51 CDT 2006 Top

SQL Server Developer >> How to use Case Statement select id, code form people_list

union
select id, code form Client_list

union
select id, code form joborder_list


Roy Harvey
Beacon Falls, CT

On Fri, 16 Jun 2006 16:22:01 -0700, Tanweer


>I tried and came up with no solution.
>I need to use Stored procedure and no dynamic sql.
>I ma using ms sql 2000 service pack 3
>
>I am using three different tables. How I can make it to run union statements
>only for those table where passing values for the variable is 1
>
>Thanks
>Tanweer
>
>



>



>
>select id, code form people_list
>union
>select id, code form Client_list
>union
>select id, code form joborder_list
>
>
>
>
>
 
 
Dan





PostPosted: Fri Jun 16 18:41:55 CDT 2006 Top

SQL Server Developer >> How to use Case Statement Try:

SELECT id, code form people_list

UNION
SELECT id, code form Client_list

UNION
SELECT id, code form joborder_list


Also, consider using UNION ALL instead of UNION unless you need to remove
duplicate rows in the result.

--
Hope this helps.

Dan Guzman
SQL Server MVP



>I tried and came up with no solution.
> I need to use Stored procedure and no dynamic sql.
> I ma using ms sql 2000 service pack 3
>
> I am using three different tables. How I can make it to run union
> statements
> only for those table where passing values for the variable is 1
>
> Thanks
> Tanweer
>
>



>



>
> select id, code form people_list
> union
> select id, code form Client_list
> union
> select id, code form joborder_list
>
>
>
>
>
>


 
 
Kalen





PostPosted: Fri Jun 16 18:43:10 CDT 2006 Top

SQL Server Developer >> How to use Case Statement First of all, CASE is an expression, not a statement, so it has to be used
as a value inside a statement. There is probably some way to get a CASE
expression to help you hear, but you might try something like this instead:










select id, code form people_list

union
select id, code form Client_list

union
select id, code form joborder_list


So the where clauses will resolve to either WHERE 1=1, which will return all
the rows, or WHERE 0 =1 which will return none of the rows.

--
HTH
Kalen Delaney, SQL Server MVP




>I tried and came up with no solution.
> I need to use Stored procedure and no dynamic sql.
> I ma using ms sql 2000 service pack 3
>
> I am using three different tables. How I can make it to run union
> statements
> only for those table where passing values for the variable is 1
>
> Thanks
> Tanweer
>
>



>



>
> select id, code form people_list
> union
> select id, code form Client_list
> union
> select id, code form joborder_list
>
>
>
>
>
>


 
 
Tanweer





PostPosted: Fri Jun 16 19:08:01 CDT 2006 Top

SQL Server Developer >> How to use Case Statement Love you guys

Great help

Thanks very much
Tanweer



> First of all, CASE is an expression, not a statement, so it has to be used
> as a value inside a statement. There is probably some way to get a CASE
> expression to help you hear, but you might try something like this instead:
>
>



>



>
> select id, code form people_list

> union
> select id, code form Client_list

> union
> select id, code form joborder_list

>
> So the where clauses will resolve to either WHERE 1=1, which will return all
> the rows, or WHERE 0 =1 which will return none of the rows.
>
> --
> HTH
> Kalen Delaney, SQL Server MVP
>
>


> >I tried and came up with no solution.
> > I need to use Stored procedure and no dynamic sql.
> > I ma using ms sql 2000 service pack 3
> >
> > I am using three different tables. How I can make it to run union
> > statements
> > only for those table where passing values for the variable is 1
> >
> > Thanks
> > Tanweer
> >
> >



> >



> >
> > select id, code form people_list
> > union
> > select id, code form Client_list
> > union
> > select id, code form joborder_list
> >
> >
> >
> >
> >
> >
>
>
>