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 |
|
curious
Starting Member
8 Posts |
Posted - 2009-01-14 : 22:21:59
|
| I'm hoping someone could help me with my query.I have a table with two columns paragraph# text1 "line one"1 "line two"1 "line three"2 "another line 1"2 "another line 2"I need to join the text lines in each paragraph together and insert then into another table asparagraph# text1 "line one" + char(13)+"line two"+char(13)+"line three"2 "another line 1"+char(13)+"another line2"any suggestions would be greatly appreciated. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-14 : 22:58:39
|
| [code]SELECT DISTINCT t.[paragraph#],STUFF(SELECT ','+ text FROM table WHERE [paragraph#]=t.[paragraph#] FOR XML PATH(''),1,1,'')FROM Table t[/code] |
 |
|
|
curious
Starting Member
8 Posts |
Posted - 2009-01-14 : 23:13:41
|
quote: Originally posted by curious I'm hoping someone could help me with my query.I have a table with two columns paragraph# text1 "line one"1 "line two"1 "line three"2 "another line 1"2 "another line 2"I need to join the text lines in each paragraph together and insert then into another table asparagraph# text1 "line one" + char(13)+"line two"+char(13)+"line three"2 "another line 1"+char(13)+"another line2"any suggestions would be greatly appreciated.
thanks for the response.I tried your code and got the following error message<<Msg 156, Level 15, State 1, Line 1Incorrect syntax near the keyword 'SELECT'.Msg 102, Level 15, State 1, Line 1Incorrect syntax near '1'.>>any ideas? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-14 : 23:36:36
|
| [code]DECLARE @Test table([paragraph#] int,[text] varchar(20))insert into @TestSELECT 1, 'line one' union allSELECT 1,'line two' union allSELECT 1, 'line three' union allSELECT 2, 'another line 1' union allSELECT 2, 'another line 2'SELECT DISTINCT t.[paragraph#],STUFF((SELECT ','+ [text] FROM @Test WHERE [paragraph#]=t.[paragraph#] FOR XML PATH('')),1,1,'')FROM @Test toutput-------------------------------paragraph# Values1 line one,line two,line three2 another line 1,another line 2[/code] |
 |
|
|
curious
Starting Member
8 Posts |
Posted - 2009-01-14 : 23:45:36
|
quote: Originally posted by curious I'm hoping someone could help me with my query.I have a table with two columns paragraph# text1 "line one"1 "line two"1 "line three"2 "another line 1"2 "another line 2"I need to join the text lines in each paragraph together and insert then into another table asparagraph# text1 "line one" + char(13)+"line two"+char(13)+"line three"2 "another line 1"+char(13)+"another line2"any suggestions would be greatly appreciated.
It worked. thanks... |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-14 : 23:55:58
|
| welcome |
 |
|
|
|
|
|
|
|