IT Community - Software Programming, Web Development and Technical Support

Concatenate row values in a table

This is a discussion on Concatenate row values in a table within the Database Support forums, part of the Web Development category; Hi, I want to concatenate row values in a table using select statement in MS SQL. For. e.g Sl. ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Database Support

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 02-07-2008, 06:35 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Thumbs up Concatenate row values in a table

Hi,

I want to concatenate row values in a table using select statement in MS SQL.
For. e.g

Sl. Name
-- ------
1 Jack
2 Paul
3 Philip

Using a select statement we should get the following output.
Jack,Paul,Philip

can anyone tell me is it possible?

Thanks
__________________
The OXYGEN
Delivers edgy, intelligent Technology to all...

Last edited by oxygen : 02-07-2008 at 10:36 PM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-08-2008, 01:49 AM
it.wily it.wily is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 89
it.wily is on a distinguished road
Smile Re: Concatenate row values in a table

hi.. oxy....


yeah.. its possible

Please try the following query


Here I followed 2 steps for concatenating row values...

First, we can get the result using "for xml raw"
then, we convert it as varchar...

declare @cols varchar(1000)

select @cols = CAST ((select filedname as col1 FROM tablename
for xml raw, elements, type).query('for $col1 in (row/col1)
return concat($col1, ",")') as varchar(1000))

select @cols


I hope it will help you
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Export table values into excel oxygen C# Programming 2 03-18-2008 02:13 AM
How to concatenate strings with Perl? amansundar Perl 3 11-28-2007 09:39 PM
How to get values from querystring? S.Vinothkumar Ruby 2 11-26-2007 06:40 AM
What is the difference between DELETE TABLE and TRUNCATE TABLE commands in SQL Server oxygen Database Support 6 11-23-2007 06:17 AM
When designing a database table, how do you avoid missing column values for non-prima Arun Database Support 2 07-18-2007 10:43 PM


All times are GMT -7. The time now is 05:56 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0