jackjohnson44
asked on
SQL concatinate
Hi,
I am trying to create a query that concatenates the columns into a single column delimited with a pipe. It works, but if one of the columns are null, the answer is null. How do I make it so my query will treat null as an empty string?
I will have the same issue with date and integer.
SELECT EmpNo, AssociationName, MemberSince, Position, AssociationName + '|' + CONVERT(varchar, MemberSince) + '|' + Position AS ProfessionalAffiliationsFu ll
FROM dbo.EmpAssociations AS e
I am trying to create a query that concatenates the columns into a single column delimited with a pipe. It works, but if one of the columns are null, the answer is null. How do I make it so my query will treat null as an empty string?
I will have the same issue with date and integer.
SELECT EmpNo, AssociationName, MemberSince, Position, AssociationName + '|' + CONVERT(varchar, MemberSince) + '|' + Position AS ProfessionalAffiliationsFu
FROM dbo.EmpAssociations AS e
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@ewangoya
It's a pain when you post a duplicate answer isn't it? <grin>
It's a pain when you post a duplicate answer isn't it? <grin>
@RQuadling
Please look carefully again. You will see a big difference
You query will put pipes even when the column value returns null
XXX||YYY or IXX|YY or IIXXX
Mine will not
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No. Please read the question ...
So NULL => ''
How do I make it so my query will treat null as an empty string?
So NULL => ''
If the output is for a pipe delimited file (like a CSV file), then having a column or three missing is pretty much going to screw up the app/process that uses the file.
ASKER
RQuadling, thanks that is what I was looking for.
How do I do the same for dates and integers?
How do I do the same for dates and integers?
cast(isnull(a_numeric_colu mn, 0) as varchar)
cast(isnull(a_date_column, '') as varchar)
cast(isnull(a_date_column,
Open in new window