gpt4 book ai didi

sql - 将 SQL Server 中的 XML 查询结果分配给 XML 类型变量会产生错误

转载 作者:行者123 更新时间:2023-12-02 01:54:43 26 4
gpt4 key购买 nike

SQL:2008 兼容性:SQL 2008 操作系统:Vista以下查询工作正常并生成 XML:

with Q1 as
(select Job, Site from JJobs where Job > 602700)
select * from Q1 where Job = 602720
for xml path('Detail'), type

我需要将其放入返回 XML 变量的函数中,因此,我更改为:

declare @xOut XML;
set @xOut =
with Q1 as
(select Job, Site from JJobs where Job > 602700)
select * from Q1 where Job = 602720
for xml path('Detail'), type

这会产生错误:关键字“with”附近的语法不正确。查询有效,但分配错误并指示查询有问题。有什么想法吗?

最佳答案

declare @xOut XML;

with Q1 as
(
select Job, Site
from JJobs
where Job > 602700
)
select @xOut = (
select *
from Q1
where Job = 602720
for xml path('Detail'), type
);

关于sql - 将 SQL Server 中的 XML 查询结果分配给 XML 类型变量会产生错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20912107/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com