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

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Display data with comma format

Author  Topic 

Mng
Yak Posting Veteran

59 Posts

Posted - 2010-03-15 : 06:41:22
I have table with data as below.

EID Ename
1 smith
2 john
3 joe
4 roy


I am looking for an output as below

Ename
Smith,John,Joe,roy

Can any one pls help me in writing a query for this?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-15 : 06:47:19
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-03-15 : 06:55:26
Try this too

select (
SELECT CAST (Ename AS VARCHAR(25)) + ',' as [text()]
FROM Employee ORDER BY EID
FOR XML PATH('') )

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-15 : 09:52:17
quote:
Originally posted by senthil_nagore

Try this too

select STUFF((
SELECT ',' + CAST (Ename AS VARCHAR(25))
FROM Employee ORDER BY EID
FOR XML PATH('') ),1,1,'')


Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/




------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -