我對數據庫電子郵件有以下T-Sql。使用xquery轉換爲html?
-- 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>