This is a discussion on concatenating multiple rows within the Sybase forums, part of the Database Server Software category; --> Hi all, I am trying to combine multiple rows value of a column into one. For example, col1 col2 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi all, I am trying to combine multiple rows value of a column into one. For example, col1 col2 col3 col4 1 a 5 b 1 a 3 c 1 a 7 d 2 a 8 e 2 a 9 x the result I would like to see is col1 col2 col3 col4 1 a 5,3,7 b,c,d 2 a 8,9 e,x I would appreciate any help. Thanks in advance |
| |||
| Hi, You could use a cursor on the query: select col1, col2, col3, col4 from mytable order by col1, col2 and then concatenate the col3 values as long as the rows have got the same col1 values and the same col2 values. The results can be inserted into a table, so you can use select * from newtable to display the final results. Hope that helps. Regards, Ulrike santosh94538@yahoo.com wrote in message news:<2a368842.0310271024.366ea7b3@posting.google. com>... > Hi all, > I am trying to combine multiple rows value of a column into one. For example, > > col1 col2 col3 col4 > 1 a 5 b > 1 a 3 c > 1 a 7 d > 2 a 8 e > 2 a 9 x > > the result I would like to see is > > col1 col2 col3 col4 > 1 a 5,3,7 b,c,d > 2 a 8,9 e,x > > I would appreciate any help. Thanks in advance |
| |||
| Hi Santosh! How about: select col1, col2, list(col3), list(col4) from mytable group by col1 Regards, Neven santosh94538@yahoo.com wrote: > Hi all, > I am trying to combine multiple rows value of a column into one. For > example, > > col1 col2 col3 col4 > 1 a 5 b > 1 a 3 c > 1 a 7 d > 2 a 8 e > 2 a 9 x > > the result I would like to see is > > col1 col2 col3 col4 > 1 a 5,3,7 b,c,d > 2 a 8,9 e,x > > I would appreciate any help. Thanks in advance |
| |||
| Thanks Ulrike for your help. Could you please tell me how to write it out. I am new to SQL. Thanks zintz@arcor.de (Ulrike Zintz) wrote in message news:<539a5d55.0310280036.446248@posting.google.co m>... > Hi, > > You could use a cursor on the query: > > select col1, col2, col3, col4 > from mytable > order by col1, col2 > > and then concatenate the col3 values as long as the rows have got the > same col1 values and the same col2 values. > > The results can be inserted into a table, so you can use select * from > newtable to display the final results. > > Hope that helps. > > Regards, > Ulrike > > santosh94538@yahoo.com wrote in message news:<2a368842.0310271024.366ea7b3@posting.google. com>... > > Hi all, > > I am trying to combine multiple rows value of a column into one. For example, > > > > col1 col2 col3 col4 > > 1 a 5 b > > 1 a 3 c > > 1 a 7 d > > 2 a 8 e > > 2 a 9 x > > > > the result I would like to see is > > > > col1 col2 col3 col4 > > 1 a 5,3,7 b,c,d > > 2 a 8,9 e,x > > > > I would appreciate any help. Thanks in advance |
| ||||
| You will find doc on T-SQL at http://sybooks.sybase.com/asg1250e.html Download doc Transact-SQL User's Guide Chapter 17 covers Cursors. Karl <santosh94538@yahoo.com> wrote in message news:2a368842.0310291044.32e4eda1@posting.google.c om... > Thanks Ulrike for your help. Could you please tell me how to write it > out. I am new to SQL. Thanks > > zintz@arcor.de (Ulrike Zintz) wrote in message news:<539a5d55.0310280036.446248@posting.google.co m>... > > Hi, > > > > You could use a cursor on the query: > > > > select col1, col2, col3, col4 > > from mytable > > order by col1, col2 > > > > and then concatenate the col3 values as long as the rows have got the > > same col1 values and the same col2 values. > > > > The results can be inserted into a table, so you can use select * from > > newtable to display the final results. > > > > Hope that helps. > > > > Regards, > > Ulrike > > > > santosh94538@yahoo.com wrote in message news:<2a368842.0310271024.366ea7b3@posting.google. com>... > > > Hi all, > > > I am trying to combine multiple rows value of a column into one. For example, > > > > > > col1 col2 col3 col4 > > > 1 a 5 b > > > 1 a 3 c > > > 1 a 7 d > > > 2 a 8 e > > > 2 a 9 x > > > > > > the result I would like to see is > > > > > > col1 col2 col3 col4 > > > 1 a 5,3,7 b,c,d > > > 2 a 8,9 e,x > > > > > > I would appreciate any help. Thanks in advance |