我试图根据列note
是否为空来将结果设为1或0
列是varchar
,我希望查询结果为该列boolean
note
值
SELECT id, product, note FROM myTABLE
我累了,
SELECT id, product, CASE WHEN ISNULL(note) THEN 0 ELSE 1 FROM myTable
但是我收到了一个错误...我相信有一个简单的解决方法,我错过了所以请帮忙。谢谢。
答案 0 :(得分:2)
尝试
SELECT id, product,CASE WHEN note IS NULL THEN 0 ELSE 1 END as SomeColumn
FROM myTable
要检查空白和null,请使用NULLIF
SELECT id, product,
CASE WHEN NULLIF(note,'') IS NULL THEN 0 ELSE 1 END as SomeColumn
FROM myTable