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)
 Take a query and paste all results in 1 line

Author  Topic 

jmiller121
Starting Member

8 Posts

Posted - 2008-08-28 : 15:26:20
Goal: Take the results of a query and place them all in one line.

For example
Field1 Field2
T1 M121
T1 M123
T1 E121
T2 L141
T2 M141
T2 E151
T2 E152

I need the result of the query to be "T1" (Field1), "M121, M123, E121," (Field2)

"In Plain English": Select the Field1 field, and for each value in Field2, take the value, add a comma and a space, then repeat for each additional value - Where the value in Field1 = "T1"

In other words, only 1 row returned per unique value in Field1

Any ideas??

Thanks for your help!

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-29 : 09:17:42
There are planty of functions here on SQLTeam for CONCATENATION.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-29 : 10:29:01
http://www.projectdmx.com/tsql/rowconcatenate.aspx
Go to Top of Page
   

- Advertisement -