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 2008 Forums
 Transact-SQL (2008)
 Concatenate multiple rows

Author  Topic 

FacE3ater
Starting Member

2 Posts

Posted - 2013-01-31 : 16:18:11
Hey guys, I am trying to gather all the text from a Description field on multiple liens, and insert it into one. It hits the first line, then doesn't find the rest. I know for this criteria, there are 4 lines with different descriptions. Here is my code:

update ps_doc_note
NOTE_TXT = cast(ps_doc_lin.DESCR as varchar)+ cast(NOTE_TXT as varchar), NOTE = cast(ps_doc_lin.DESCR as varchar)+ cast(NOTE_TXT as varchar)
from PS_DOC_LIN
full join ps_doc_note
on PS_DOC_LIN.DOC_ID = PS_DOC_NOTE.DOC_ID
where item_no = '13' and ps_doc_lin.DOC_ID = 108109492327


Thanks,

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-01 : 02:46:06
[code]
update ps_doc_note
NOTE_TXT = STUFF((SELECT ' ' + DESCR FROM PS_DOC_LIN WHERE DOC_ID = ps_doc_note.DOC_ID FOR XML PATH('')),1,1,'')
FROM ps_doc_note
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

FacE3ater
Starting Member

2 Posts

Posted - 2013-02-01 : 09:01:44
Worked! Awesome thanks!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-01 : 12:40:08
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -