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)
 Columns in row

Author  Topic 

cindylee
Yak Posting Veteran

55 Posts

Posted - 2007-04-11 : 21:32:25
Hi ppl,
I would like to display a distinct columns in table in row format.

Ex:
col1
1
5
6
8
9
44

like to display in the following format:
1,5,6,8,9,44

anyhelp much appreciated
C

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-11 : 21:35:22
see http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx


KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-12 : 07:37:22
Also, if you use front end application, do concatenation there

Madhivanan

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

mahesh_bote
Constraint Violating Yak Guru

298 Posts

Posted - 2007-04-12 : 11:17:56
quote:
Originally posted by cindylee

Hi ppl,
I would like to display a distinct columns in table in row format.

Ex:
col1
1
5
6
8
9
44

like to display in the following format:
1,5,6,8,9,44

anyhelp much appreciated
C



try this with case stmt ...

DECLARE @STR VARCHAR(1000)
SELECT @STR = (CASE WHEN @STR IS NULL THEN <ur field> ELSE @STR + ', ' + <ur field> END)
FROM <ur table>

SELECT
@STR AS CSV_STRING

Mahesh
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-04-12 : 14:29:15
A simple search of the site provides your answer

http://www.sqlteam.com/item.asp?ItemID=2368



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -