SQL QUERY中的子句

时间:2011-01-31 08:03:54

标签: sql

如何在then子句中添加不等于操作? 例如

@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

1 个答案:

答案 0 :(得分:5)

摆脱CASE表达式:

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