我有以下用于 Sql server 2008 表的 xquery。
declare @tableName sysname = 'tableName'
declare @colNames xml = (select COLUMN_NAME from INFORMATION_SCHEMA.columns where TABLE_NAME = @tableName for xml path(''), elements)
select @colNames.query('<html><body>
<table>
<tr>
{
for $c in /COLUMN_NAME
return data($c)[1]
}
</tr>
</table>
</body></html>
')
但是,它返回以下 xml。
<html>
<body>
<table>
<tr>col1col2col3col4col5</tr>
</table>
</body>
</html>
预期的结果是
<html>
<body>
<table>
<tr><th>col1</th><th>col2</th><th>col3</th><th>col4</th><th>col5</th></tr>
</table>
</body>
</html>
我试图更改return data($c)[1]
为concat("<th>", data($c)[1], "</th>")
. 然而,<
and>
被逃到<
and >
?