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:
Declare @people_list int
Declare @client_list int
Declare @joborder_list int
set @people_list=1
set @client_list =0
set @joborder_list =1
select id, code form people_list
where @people_list=1
union
select id, code form Client_list
where @client_list = 1
union
select id, code form joborder_list
where @joborder_list =1
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
[quoted text, click to view] "Tanweer" <Tanweer@discussions.microsoft.com> wrote in message
news:86921632-36FA-4AD8-857D-4A639725B574@microsoft.com...
>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
>
>
> Declare @people_list int
> Declare @client_list int
> Declare @joborder_list int
>
> set @people_list=1
> set @client_list =0
> set @joborder_list =1
>
> select id, code form people_list
> union
> select id, code form Client_list
> union
> select id, code form joborder_list
>
>
>
>
>
>