Sql 当isnull(';sdas';0)=0时选择大小写,然后选择';嗨';其他';再见';以'结束;价值';

Sql 当isnull(';sdas';0)=0时选择大小写,然后选择';嗨';其他';再见';以'结束;价值';,sql,sql-server,tsql,Sql,Sql Server,Tsql,下面的查询 select case when isnull('23',0)=0 then 'hi' else 'bye' end as 'Value' 返回bye 但是 在MS-SqlServer2008R2中返回以下错误消息 Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value 'sdas' to data type int. 你能澄清一下它是在哪个阶段进行转换的吗?'2

下面的查询

select case when isnull('23',0)=0 then 'hi' else 'bye' end as 'Value'
返回
bye

但是

在MS-SqlServer2008R2中返回以下错误消息

Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value 'sdas' to data type int.

你能澄清一下它是在哪个阶段进行转换的吗?

'23'
可以动态转换为int,但是
'sdas'
不能。 为所有变量设置字符串(varchar)-类型:

select case when isnull('sdas','0')='0' then 'hi' else 'bye' end as 'Value'

问题是将
sdas
转换为整数
0
。您可以使用
is null
运算符,而不是使用
isnull
函数:

select case when 'sdas' is null then 'hi' else 'bye' end as 'Value' 
select case when 'sdas' is null then 'hi' else 'bye' end as 'Value'