June 12, 2003 at 3:41 pm
Hi,
I have been trying to write a simple SQL query (if feasiable) to join two column (col1 and col2), each on has following data
Col1 Col2 (Col2 has NULL values)
james NULL
scott Bryan
john Null
richard Null
steve johnson
I want to concatenate both columns into one single column when I display, something like
result
james
Scott,Bryan
john
richard
steve, johnson
all the help will be greatly appreciated,
thanks in advance,
vijju
June 12, 2003 at 4:17 pm
June 12, 2003 at 4:49 pm
Try moving the ',' into the ISNULL function.
SELECT Col1 + ISNULL(', ' + Col2, '')
This way the comma will show up only when you have a non null value in Col2
June 12, 2003 at 4:54 pm
Another way is
SELECT
CASE WHEN col2 IS NULL THEN col1
ELSE col1+ ', ' +col2 END
FROM ....
June 13, 2003 at 7:19 am
thank you for all your help, it worked like a charm.
vijju
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply