我在SQL中有一列是varchar。我需要它来返回任何带有值的东西。
例子...
select * from students where StudentID <> ''
这是正确的做法吗?我试过不为null,但它也会返回任何为空的内容。
谢谢
我建议使用合并:
select * from students where coalesce(StudentID, '') <> ''
这会将null转换为空字符串并禁止使用它们。这还有限制空字符串的额外好处。
空值不等于任何东西,甚至不等于空值,因此简单的方法<>
不起作用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句