Sql row adding issue
3 answers
You are looking for a function ISNULL
:
SELECT ISNULL(a.one,'') + ' test ' + ISNULL(b.two , '')
from table1 a
right join table1 b
on a.id =b.id
If the first argument to the function ISNULL
is zero, then the second argument is provided. This way, none of the concatenated fields will return null and you will end up with a string, not null.
+3
a source to share
There are several options depending on which one you want
-- leading/trailing spaces on test
SELECT ISNULL(a.one,'') + ' test ' + ISNULL(b.two , '')
-- no spacing around test
SELECT ISNULL(a.one,' ') + 'test' + ISNULL(' ' + b.two, '')
-- do you want the word test at all if one is blank?
SELECT ISNULL(a.one + ' test','') + ISNULL(' ' + b.two, '')
+1
a source to share