Posted by: NIRAVANA75062 May 31, 2007
SQL - Help please
Login in to Rate this Post:     0       ?        
if u only need result set can u try this .
select
name,
address,
state,
Phone,
(case when (rtrim(Extra1) is not null and rtrim(Extra1) <>'') then rtrim(Extra1) else '' end +
case when (rtrim(Extra2) is not null and rtrim(Extra2) <>'') then ',' + rtrim(Extra2) else '' end +
case when (rtrim(Extra3) is not null and rtrim(Extra3) <>'') then ','+ rtrim(Extra3) else '' end ) as Concatinated

FROM testtable

I might be wrong about this query but i think u can apply same kind of logic.

if u need to create a new target table, then create a store proc which will create new table and insert all those values into that table.
Read Full Discussion Thread for this article