Aliasing a FOR XML PATH result(别名 FOR XML PATH 结果)
问题描述
我想为以下输出添加别名:
I want to alias the output of the following:
-- Test table with some rubbish data
DECLARE @Test TABLE
(
Names [varchar](20)
)
INSERT INTO @Test
SELECT 'Simon'
-- Query returns but with XML_<GUID> alias
SELECT
Names
FROM
@Test t
FOR XML PATH ('Test')
因此,为了争论,我想给它一个别名,而不是 XML_GUID 的列标题.我似乎无法得到它.有谁知道怎么做?我尝试以下示例:http://social.msdn.microsoft.com/Forums/nl/sqlxml/thread/1605c722-6388-40ff-9ab5-a3817a1db81f 但我似乎无法让它返回.我总是遇到错误,说第 1 列没有名称.
So rather than a column header of XML_GUID I want to give it an alias of say 'Test' for sake of argument. I can't seem to get it. Anyone know how? I tried following an example from here: http://social.msdn.microsoft.com/Forums/nl/sqlxml/thread/1605c722-6388-40ff-9ab5-a3817a1db81f but I can't seem to get it to return. I always run into the error that says the is no name for column 1.
感谢任何帮助.
谢谢,
西蒙
推荐答案
使其成为子查询:
select (
SELECT
Names
FROM
@Test t
FOR XML PATH ('Test'),TYPE) as Test
子查询产生值但从不提供列的名称.我还指定了 ,TYPE 因为否则它会强制将结果转换为 varchar(max),而您可能希望将其保留为 xml.
Subqueries produce values but never provide a name for a column. I also specified ,TYPE because otherwise it forces a conversion to varchar(max) on the result, whereas you presumably want to keep it as xml.
这篇关于别名 FOR XML PATH 结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:别名 FOR XML PATH 结果
基础教程推荐
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 在多列上分布任意行 2021-01-01
- oracle区分大小写的原因? 2021-01-01
