I have a database table looks like this:
EVENT_ID TEXT_FRO TEXT_TO
55001 05
55001 05 10
55001 10 15
55001 15 20
55001 20 30
56215 06 11
56215 11 22
I need to write a query (or a SP) to produce a result set to list all movements for each distinct event_ID which looks like this:
Event ID Movements
55001 05 10 15 20 30
56215 06 11 22
How can I do that?
*Edit to simplify the example
It is pretty straight forward if you use a function and a cursor:
You have to create a function to assemble the concatenated string:
It is more efficient if you only call the function one time per unique EVENT_ID, so we select the
distinctEVENT_ID in a sub-query:And then cleanup:
This is the result looks like this: