Extending this original question
I am using SQL Server Express 2017
Pretending this is my source table:
+-------------+---------------------------+
| ID | Name | Age | HairColor | HasCar |
+-------------+---------------------------+
| 1 | Bert | 25 | blonde | 1 |
| 2 | Agnes | 61 | white | 0 |
| 3 | Diane | 43 | brunette | 1 |
+-------------+---------------------------+
How can get a result looking like this?
<MyRootElement>
<MyGroupingTag Group="1">
<MyTag Value="1" />
<MyTag Value="Bert" />
<MyTag Value="25" />
<MyTag Value="blonde" />
<MyTag Value="1" />
</MyGroupingTag>
<MyGroupingTag Group="2">
<MyTag Value="2" />
<MyTag Value="Agnes" />
<MyTag Value="61" />
<MyTag Value="white" />
<MyTag Value="0" />
</MyGroupingTag>
<MyGroupingTag Group="3">
<MyTag Value="3" />
<MyTag Value="Diane" />
<MyTag Value="43" />
<MyTag Value="brunette" />
<MyTag Value="1" />
</MyGroupingTag>
</MyRootElement>
Because of the Group attribute in MyGroupingTag I can't use something like
SELECT... FOR XML PATH('MyTag'), ROOT('MyGroupingTag')
The Group itself is a simple row count.