Click here to Skip to main content

Eligible Contests

Tagged as

Stats

8.9K views
1 bookmarked

Select a column in a comma separated row in SQL

10 May 2011CPOL
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
SQL
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

pankajupadhyay29
Architect
India India
• An Architect, developer, trainer, and student
• 10 years of experience in Architecture and Development of enterprise applications
• Extensive knowledge in designing and developing Web-based enterprise applications using open source and Microsoft Technologies
• Extensive experience in Angular, AngularJS, ReactJs, NodeJs, JavaScript, ASP.Net, C#, CSS, HTML

Comments and Discussions

 
-- No messages could be retrieved (timeout) --