If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Sybase > How to concatenate rows

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-23-10, 14:11
Fatbob73 Fatbob73 is offline
Registered User
 
Join Date: Sep 2008
Posts: 13
How to concatenate rows

Hi everyone,

I have a table that looks like this...

PID evacCodeNoteCd
12 EVAC1OXY
12 EVAC2IV
12 EVACOTH

and I'd like to return this...

EVAC1OXY/EVAC2IV/EVACOTH

So how can I concatenate multiple rows into one field?
Reply With Quote
  #2 (permalink)  
Old 07-24-10, 12:14
reddy_546 reddy_546 is offline
Registered User
 
Join Date: May 2010
Location: Hyderabad, India
Posts: 16
Declare @lvcConcat Varchar(8000)
,@lvcLocalVar
SELECT @lvcConcat = ''
Declare cursor concat_rows for
select evacCodeNoteCd from Table_Name
Open Cursor
Fetch cursor into @lvcLocalVar
WHILE(@@sqlstatus = 0)
BEGIN
SELECT @lvcConcat = @lvcConcat+ @lvclocalVar
Fetch cursor into @lvcLocalVar
END
SELECT LTRIM(RTRIM(@lvcConcat))
__________________
-PavanKumar M Reddy
Reply With Quote
  #3 (permalink)  
Old 07-26-10, 11:26
Fatbob73 Fatbob73 is offline
Registered User
 
Join Date: Sep 2008
Posts: 13
Thanks for the suggest. Using cursors works, but I was hoping there was a simpler solution.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On