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
 SQL Server Development (2000)
 Query Issue

Author  Topic 

sqldba2k6
Posting Yak Master

176 Posts

Posted - 2006-08-04 : 14:09:36
I need help in getting the desired output.

Declare @Temp Table(id int,SomeValue VarChar(2))


Insert Into @Temp(id,SomeValue) Values (14, 10)
Insert Into @Temp(id,SomeValue) Values (14, 20)
Insert Into @Temp(id,SomeValue) Values (14, 30)
Insert Into @Temp(id,SomeValue) Values (15, 10)
Insert Into @Temp(id,SomeValue) Values (15, 20)
Insert Into @Temp(id,SomeValue) Values (15, 30)


Declare @Result VarChar(8000)

Select @Result = coalesce(@Result+','+SomeValue, @Result, SomeValue) From @Temp

Select @Result


Desired Results
------------

Id Somevalue
-- --------
14 10,20,30
15 10,20,30

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-08-04 : 14:11:38
Try :
http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx

Srinika
Go to Top of Page

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2006-08-04 : 17:48:40
Pivot Tables/Cross Tab reports are a big pain in SQL, the Article that helped me the most was the following.

http://www.databasejournal.com/features/mssql/article.php/10894_3516331_2

Hope it helps.
Go to Top of Page
   

- Advertisement -