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)
 Joining strings

Author  Topic 

curious
Starting Member

8 Posts

Posted - 2009-01-14 : 23:16:51
I'm hoping someone could help me with my query.
I have a table with two columns

paragraph# text
1 "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 as

paragraph# text
1 "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-15 : 00:09:54
Duplicate
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=117867
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-01-15 : 23:25:06
DECLARE @temp table(parano int,text varchar(20) )
insert into @temp
SELECT 1, '"line one"' union all
SELECT 1,'"line two"' union all
SELECT 1, '"line three"' union all
SELECT 2, '"another line 1"' union all
SELECT 2, '"another line 2"'


SELECT DISTINCT t.parano,STUFF((SELECT '+'+ [text] FROM @temp WHERE parano=t.parano FOR XML PATH('')),1,1,'')
FROM @temp t



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-16 : 00:19:22
quote:
Originally posted by Nageswar9

DECLARE @temp table(parano int,text varchar(20) )
insert into @temp
SELECT 1, '"line one"' union all
SELECT 1,'"line two"' union all
SELECT 1, '"line three"' union all
SELECT 2, '"another line 1"' union all
SELECT 2, '"another line 2"'


SELECT DISTINCT t.parano,STUFF((SELECT '+'+ [text] FROM @temp WHERE parano=t.parano FOR XML PATH('')),1,1,'')
FROM @temp t






this is same solution i provided in other link. please dont repeat solutions
Go to Top of Page
   

- Advertisement -