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 2000 Forums
 Transact-SQL (2000)
 How to show column horizontally

Author  Topic 

real_pearl
Posting Yak Master

106 Posts

Posted - 2004-08-12 : 08:47:57
Is it possible to get the columns values horizontally with a comma seperator like this

1,2,3,4,5,6,7,8 INSTEAD OF

1
2
3
4
5
6
7

without a loop just throuh SELECT query
8

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-12 : 08:51:09
Declare @ValueList varchar(1000)
SELECT @ValueList = COALESCE(@ValueList + ', ', '') + col1
FROM MyTable
select @ColumnList

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

real_pearl
Posting Yak Master

106 Posts

Posted - 2004-08-12 : 09:02:39
Spirit :) Thanks a lot

Dear if we have around one million or more records then there will be a problem with the varchar(8000) data type. Is there any other way to solve this issue, please tell me
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2004-08-12 : 09:07:20
most basic question: what would you want a million items in a comma seperate list for? knowing that might deliver a better (faster/more futureproof) solution to your overall problem.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-12 : 09:07:57
you could split them in chunks of 8000.

...
FROM MyTable
where id<8000

...
FROM MyTable
where id between 8000 and 16000

and then put select them...



Go with the flow & have fun! Else fight the flow :)
Go to Top of Page
   

- Advertisement -