如何通过TSQL中的空值检查将值设置为true或false?
问题描述:
如果字段不为NULL,返回TRUE的正确语法是什么?如果TSQL中为空,则返回FALSE?
What is the right syntax to return TRUE if the field is not NULL and to return FALSE if it is NULL in TSQL?
SELECT -- here return TRUE if table.Code IS NOT NULL. And FALSE otherwise
FROM table
答
select case
when code IS NULL then 'false'
else 'true'
end as result
from the_table