我想對2列結果做一個例子。我該怎麼做呢?TSQL - 如何使用2列的case語句?
例如爲:
SELECT CASE amount=100 AND DATE IS NOT NULL WHEN 0 THEN 'Something' ELSE ''
類似的東西?
我想對2列結果做一個例子。我該怎麼做呢?TSQL - 如何使用2列的case語句?
例如爲:
SELECT CASE amount=100 AND DATE IS NOT NULL WHEN 0 THEN 'Something' ELSE ''
類似的東西?
select case
when amount = 100 and date is not null then 'something'
else 'something else'
end
這是一個 「被搜索的情況下的表達」(see MSDN):
CASE
WHEN Boolean_expression THEN result_expression [ ...n ]
[ ELSE else_result_expression ] END
select someColumnName,
case
when amount = 100 AND someothercondition then 'XXX'
when amount = 1000 AND anothercondition then 'YYY'
else 'WWW'
end as "MyColumnName"
from myTable
select
case
when
amount = 100
and date is not null
then
'0'
else
'something else'
end
查找SELECT WHEN
SELEC t case when amount = 100 and date is not null then'something'else'something when amount = 0 then'something else'end as MyColumnName
打我2秒! – 2009-03-03 06:18:35