Kishh
Kishh

Reputation: 2065

Where Clause in SQL QUERY

How to add not equal to operation in then clause ? For Example

@Sample varchar(50)


Select * from table
Where 
ISNULL(table.column1, '') = CASE WHEN @Sample = '1' THEN '500' 
                                 WHEN @Sample = '0' THEN '600' 
                                 ELSE (NOT EQUAL TO 500)
                            END

Upvotes: 0

Views: 160

Answers (1)

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239814

Get rid of the CASE expression:

select * from  table
where
    (@Sample='1' and table.column1 = '500') or
    (@Sample='0' and table.column1 = '600') or
    (@Sample not in ('0','1') and COALESCE(table.column1,'') <> '500')

Upvotes: 5

Related Questions