Multiple rows in a single row with separator in SqlServer

No.of Views1122
Bookmarked0 times
Downloads 
Votes0
By  vinothnat   On  15 Feb 2010 22:02:37
Tag : Sql Servers , T-SQL
Multiple rows in a single row with separator in SqlServer
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 


Here is a simple way to make a single row value from multiple rows with a separator in SqlServer.


I have a table like the following…

Table Name: People

{codecitation class="brush: sql; gutter: true;" width="500px"}


select * from people

{/codecitation}

alt

Now I need the ‘Name’ column values where matching the value of ‘aaaa’ in to a single row. For this I have tried to make a query.

Just use the following query to get the solution.



{codecitation class="brush: sql; gutter: true;" width="500px"}


declare @res varchar(1000)
select @res = coalesce(@res + ',', '') +Name
from  people
WHERE Name = 'aaaa'

select @res

{/codecitation}

Result

alt



...S.VinothkumaR.

 
Sign Up to vote for this article
 
About Author
 
vinothnat
Occupation-Not Provided
Company-Not Provided
Member Type-Junior
Location-Not Provided
Joined date-03 Jun 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top