SQL - Replacing an is null integer with a varchar

2019-02-21 00:31发布

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'))

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:

the conversion failed when converting the varchar value to a data type int.

How do I get past this?

1条回答
霸刀☆藐视天下
2楼-- · 2019-02-21 01:02

Replace this:

(personid+ISNULL(personid,'no person'))

With this:

(ISNULL(CAST(personid as varchar(31)),'no person')) AS personId
查看更多
登录 后发表回答