How to Combine multiple column in a table and create separate Column in SQL and insert a single pipe '|' between the data even though some column has empty field.
I have tried using concat but got multiple pipe if there is empty field
select top 4 concat(code2_1,'|',code2_2,'|',Code2_3,'|',code2_4) from
Sourcesql
above is a table
for example 4 th row i need PT01|PT02|PT04
I didnt get the answer even i find like below query then how can my above query is duplicate
SELECT
STUFF(
COALESCE('|' + code2_1, '') +COALESCE('|' +code2_2, '') +COALESCE('|'+
code2_3, '') +COALESCE('|'+ code2_4, ''),
1, 0, '') AS bar
FROM Sourcesql