declare @T table
(
ProblemType varchar(10),
Onset date,
DiagnosisStatus varchar(10)
)
insert into @T values
( 'Ulcer', '01/01/2008', 'Active'),
( 'Edema', '02/02/2005', 'Active')
select
(select 1 as 'th/@size', 'Problem' as th for xml path(''), type),
(select 1 as 'th/@size', 'Onset' as th for xml path(''), type),
(select 1 as 'th/@size', 'Status' as th for xml path(''), type)
union all
select
(select 1 as 'td/@size', p.ProblemType as 'td' for xml path(''), type),
(select 1 as 'td/@size', p.Onset as 'td' for xml path(''), type),
(select 1 as 'td/@size', p.DiagnosisStatus as 'td' for xml path(''), type)
from @T p
for xml path('tr')
Результат:
<tr>
<th size="1">Problem</th>
<th size="1">Onset</th>
<th size="1">Status</th>
</tr>
<tr>
<td size="1">Ulcer</td>
<td size="1">2008-01-01</td>
<td size="1">Active</td>
</tr>
<tr>
<td size="1">Edema</td>
<td size="1">2005-02-02</td>
<td size="1">Active</td>
</tr>