开发者

Where Clause in SQL QUERY

开发者 https://www.devze.com 2023-02-07 10:05 出处:网络
How to add not equal to operation in then clause ? For Example @Sample varchar(50) Select * from table Where

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


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')
0

精彩评论

暂无评论...
验证码 换一张
取 消