Click here to Skip to main content
11,573,084 members (68,125 online)
Click here to Skip to main content

Tagged as

Select a column in a comma separated row in SQL

, 10 May 2011 CPOL 5.3K 1
Rate this:
Please Sign up or sign in to vote.
Nice one but it did not handle null values you can change it as following to handle null valuescreate table #TABLE_1 (COLUMN_1 varchar(5))insert into #TABLE_1select 'A'union allselect 'B'union allselect 'C'union allselect 'D'union allselect 'E'union allselect...
Nice one but it did not handle null values you can change it as following to handle null values
create table #TABLE_1 (COLUMN_1 varchar(5))
insert into #TABLE_1
select 'A'
union all
select 'B'
union all
select 'C'
union all
select 'D'
union all
select 'E'
union all
select null
declare @list varchar(max)
select @list=COALESCE(@list+', ','')+ isnull(COLUMN_1,'NULL') from #TABLE_1
select @list
drop table #TABLE_1

This is just a update in existing trick..

Thanks

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

code in play
Software Developer (Senior)
India India
4+ year experience in Microsoft technologies(C#.Net,ASP.Net, SQL server and Sharepoint).

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150624.2 | Last Updated 11 May 2011
Article Copyright 2011 by code in play
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid