From: Rajeev on
Hi,

I have a below query.

Select * from Employees(NOLOCK) Where HomeCountry = 'USA' AND
HostCountry = 'JAPAN'

In some places i want to use 'OR' in place of 'AND' in the WHERE
Clause based on one Flag ANDORFLAG.

IF ANDORFLAG = 1 THen i want to use 'AND' in the WHERE CLAUSE.
IF ANDORFLAG = 0, THEN i want to use 'OR' in the WHERE CLAUSE.

I tried so many combinations using the CASE, but none of them is
working. Could you please help me how can i achieve this. Below is the
one of the example i tried.

select * from #temp where HomeCOuntry = @ShadowPayrollCountry
case @andorflag when 0 then @and
when 1 then @or end
HostCOuntry = @ShadowPayrollCountry
From: Tom Cooper on
Answered in .Server group. Please do not multipost.
Tom

"Rajeev" <rajeev.rajput(a)gmail.com> wrote in message
news:a2714a78-2e47-45ad-a854-4b0fac73c44a(a)y22g2000prd.googlegroups.com...
> Hi,
>
> I have a below query.
>
> Select * from Employees(NOLOCK) Where HomeCountry = 'USA' AND
> HostCountry = 'JAPAN'
>
> In some places i want to use 'OR' in place of 'AND' in the WHERE
> Clause based on one Flag ANDORFLAG.
>
> IF ANDORFLAG = 1 THen i want to use 'AND' in the WHERE CLAUSE.
> IF ANDORFLAG = 0, THEN i want to use 'OR' in the WHERE CLAUSE.
>
> I tried so many combinations using the CASE, but none of them is
> working. Could you please help me how can i achieve this. Below is the
> one of the example i tried.
>
> select * from #temp where HomeCOuntry = @ShadowPayrollCountry
> case @andorflag when 0 then @and
> when 1 then @or end
> HostCOuntry = @ShadowPayrollCountry


 | 
Pages: 1
Prev: Round Function
Next: Case construct in function