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.
Author |
Topic |
bi89405
Starting Member
35 Posts |
Posted - 2013-05-16 : 11:09:14
|
Hello,I have a table that stores descriptions of an index in multiple lines. Each line is numbered sequentially. I would like to use a cursor that will be able to write the descriptions in a single row. Here is an example:IndexNo LineNo Description1 1 Joe went to school1 2 today and come home1 3 at 3pm.The goal of the output should be:IndexNo Description1 Joe went to school today and come home at 3pm.TIA,ZH |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-05-16 : 11:21:43
|
Don't use cursor. That is going to be slow. Do it like shown belowSELECT [Index], LTRIM( (SELECT ' '+[Description] FROM Tbl t2 WHERE t2.[Index] = t1.[Index] ORDER BY [LineNo] FOR XML PATH('') )) AS [Description]FROM (SELECT DISTINCT [Index] FROM Tbl) t1; |
|
|
|
|
|