The query results are multiple rows and one column. Now we need to splice these results into a string!
Select [values] = stuff (select ',' + coal_id from cbm_well_coalbed_info t for XML Path (''), 1, 1 ,'')
It's a bit confusing. I have never touched on such a usage. It's very powerful!
1. for XML Path
Convert the query result to XML
A. Select well_id, coal_id from cbm_well_coalbed_info t for XML Path ('liuxm ')
The result is as follows:
<Liuxm>
<Well_id> 8ad882351ede89c6011eecb09b290002 </well_id>
<Coal_id> 8ad882351ec8d47c011ec99e01b6002b </coal_id>
</Liuixm>
2. Stuff Function
Deletes a string of the specified length and inserts a group of characters at the specified start point.
Stuff (character_expression, start, length, character_expression)
Character_expression: Operator character,
Start: the start point of deletion and insertion,
Length: delete length,
Character_expression: the character to be inserted.
Record it first, and then study again...