Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果给定列有任何数据,我想返回 1 或 0(或 true 或 false,或 true 或 null,或任何最简单的)。无论该字段是否有数据,其他列仍然会被返回。下面是正确的方法吗?谢谢
SELECT varchar_field IS NOT NULL, some_other_fields
您可以使用case声明
case
CASE WHEN varchar_field is null THEN 1 ELSE 0 END
尝试
SELECT ISNULL(varchar_field), some_other_fields
如果你想要 0 而varchar_field不是null
varchar_field
null
SELECT NOT ISNULL(varchar_field), some_other_fields
如果你想要 1 当varchar_field不是null