0

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?

0

1 Answer 1

2

Replace this:

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

With this:

(ISNULL(CAST(personid as varchar(31)),'no person')) AS personId
Sign up to request clarification or add additional context in comments.

3 Comments

Sorry, I just checked now and the field name is actually stored as 'NULL' instead of not showing anything. How would I go about converting that to something else in the query result? Thanks !
But this still worked as the personid field is INT so I had to change it anyway! Thanks a lot bro!
I'm confused as to where you say they are storing 'NULL'. If the personId field is INT, they can't be storing the string 'NULL' in it. If you mean the column header doesn't have a name, that can be fixed with a alias. See my edited answer above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.