user1077928
user1077928

Reputation: 1

TSQL Dynamic Where

I would like to do something ike this.

declare @var1 as integer

Select * from table name 
where id
If @var1 = 1 then
 21 
elseif  @var1 = 2
 <>21

All I would like to know is if this is possible. The only thing that needs to change is the comparison operator.

Upvotes: 0

Views: 125

Answers (1)

IUnknown
IUnknown

Reputation: 22448

where ( @var1 = 1 and id = 21) or (@var1 = 2 and id <> 21)

Upvotes: 3

Related Questions