SQL Server 中的 ISNULL 行为
根据我的理解 IsNull 函数检查第一个值是否为空或空白,然后返回下一个值。
SELECT ISNULL(1,getdate())
但上面的语句给出了错误。任何人都可以帮助强调原因吗?
As per my understanding IsNull Function checks the first value if its null or blank then it returns the next value.
SELECT ISNULL(1,getdate())
but the above statement is giving error. Can any one help to highlight the reason?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不允许从数据类型 datetime 到 int 的隐式转换,将第一个值设置为 char
BTW,只是要注意 ISNULL 不是 ANSI 专有的,并且只接受 2 个参数,COALESCE 接受更多参数
下面的语句是不正确的
它不关心空白
运行这个
ISNULL和COALESCE之间的另一个区别是ISNULL将返回与第一个参数相同的长度
运行这个
Implicit conversion from data type datetime to int is not allowed, make the first value a char
BTW, just be aware that ISNULL is not ANSI is proprietery and only accepts 2 parameters, COALESCE accepts a lot more
This statement below is incorrect
it doesn't care for blanks
run this
another difference between ISNULL and COALESCE is that ISNULL will return the same length as the first parameter
run this
我猜您正在尝试用日期替换整数。也许可以试试这个 SELECT ISNULL(1,2) 。
I guess you are trying to replace an Integer with a Date. Try this SELECT ISNULL(1,2) maybe instead.
你可以让它自动播放,但我真的不推荐它。对于其他人来说,非常不清楚它想做什么:
You can get it to autocast doing this but I really would not recommend it. It's super unclear to someone else looking at this what it is trying to do: