SQL-用varchar替换为null的整数 [英] SQL - Replacing an is null integer with a varchar
本文介绍了SQL-用varchar替换为null的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果试图在select语句中包含空值,则尝试用新的varchar
字符串替换列:
I am trying to replace a column with a new varchar
string if there is null values in it in a select statement:
(personid + ISNULL(personid, 'no person'))
我不尝试更新它,只是在查询结果中将值显示为"no person".
I'm not trying to update it, only show the value as 'no person' in the query result.
但是我收到一个错误消息:
But I am getting an error saying:
将varchar值转换为int数据类型时,转换失败.
the conversion failed when converting the varchar value to a data type int.
我该如何克服?
推荐答案
替换此:
(personid+ISNULL(personid,'no person'))
与此:
(ISNULL(CAST(personid as varchar(31)),'no person')) AS personId
这篇关于SQL-用varchar替换为null的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文