I have a simple query over a table, which returns results like the following:
id id_type id_ref
2702 5 31
2702 16 14
2702 17 3
2702 40 1
2703 23 4
2703 23 5
2703 34 6
2704 1 14
And I would like to merge the results into a single row, for instance:
id concatenation
2702 5,16,17,40:31,14,3,1
2703 23,23,34:4,5,6
2704 1:14
Is there any way to do this within a trigger?
NB: I know I can use a cursor, but I would really prefer not to unless there is no better way.
The database is Sybase version 12.5.4.
Since it’s rather difficult to get this done in Sybase using a select statement I would suggest a
whileloop like the following. While loops are preferred over cursors for being much faster. Assuming that table name is MYTABLE:EDIT
The following version is about 45% faster