我有以下用于数据库电子邮件的 T-Sql。
-- create proc TableToHtml @table varchar(max) as
declare @table varchar(max) = '(select 1 a, ''one'' b union all select 2, ''two'') t '
declare @sql varchar(max) = '
declare @xml xml = (
select * from ' + @table + '
for xml path(''tr''), root(''table'')
);
select @xml'
declare @tmp table (x xml)
insert into @tmp exec(@sql)
declare @x xml = (select x from @tmp)
select @x
它返回
<table>
<tr>
<a>1</a>
<b>one</b>
</tr>
<tr>
<a>2</a>
<b>two</b>
</tr>
</table>
是否可以编写 xquery 让它返回以下 html?
<table>
<tr>
<th>a</th>
<th>b</th>
</tr>
<tr>
<td>1</td>
<td>one</td>
</tr>
<tr>
<td>2</td>
<td>two</td>
</tr>
</table>