以下查询
select case when isnull('23',0)=0 then 'hi' else 'bye' end as 'Value'
返回bye
BUT
select case when isnull('sdas',0)=0 then 'hi' else 'bye' end as 'Value'
在MS-SqlServer2008R2中返回以下错误消息
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value 'sdas' to data type int.
你能澄清它在哪个阶段完成转换
答案 0 :(得分:1)
'23'
可以动态转换为int,但'sdas'
不能。
对所有变量采用string(varchar)-type:
select case when isnull('sdas','0')='0' then 'hi' else 'bye' end as 'Value'
答案 1 :(得分:0)
问题是将sdas
转换为整数0
。您可以使用isnull
运算符
is null
函数
select case when 'sdas' is null then 'hi' else 'bye' end as 'Value'