Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 concatenation of rows
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

United Kingdom
1 Posts

Posted - 02/04/2013 :  06:03:41  Show Profile  Reply with Quote
Hi ,

I have a situation where i have to concatenate rows based of group of value or without group, i don't want to use tsql. can any one let me know wether we have any function for it.

train_no direction
123 south-east
124 south-east
125 south-east
126 south-east
131 south-west
132 south-west
156 east

I want result as below
train,no direction
(123,124,125,126) South-East
(131,132) South-West
(156) esst

Please help

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 02/04/2013 :  06:11:07  Show Profile  Reply with Quote
	STUFF(trains,1,1,'') AS trains,
	(SELECT DISTINCT direction FROM TheTable) a
		SELECT ',' + CAST( train_no AS varchar(32))
		FROM TheTable b 
		WHERE b.direction = a.direction
	) c(trains)
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000