gpt4 book ai didi

tsql - T-SQL 中的变量

转载 作者:行者123 更新时间:2023-12-04 06:30:37 25 4
gpt4 key购买 nike

我的 T-SQL 代码如下:

declare @xml xml = N'
<a abb="122">
<b>
</b>
</a>
<a abb="344">
<b>
</b>
</a>';

declare @T table (XMLCol xml);

insert into @T values (@xml);

declare @sql varchar(max);
set @sql = 'update @T set
XMLCol.modify(''
replace value of (/a/@abb)[1]
with 888'');';
exec (@sql);

当我执行时,出现一个故障段:
Msg 1087, Level 15, State 2, Line 1
Must declare the table variable "@T".

如何声明变量@T 才能理解?

最佳答案

您可以使用临时表而不是表变量。

declare @xml xml = N'
<a abb="122">
<b>
</b>
</a>
<a abb="344">
<b>
</b>
</a>';

create table #T (XMLCol xml);

insert into #T values (@xml);

declare @sql varchar(max);
set @sql = 'update #T set
XMLCol.modify(''
replace value of (/a/@abb)[1]
with 888'');';
exec (@sql);

drop table #T

关于tsql - T-SQL 中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5456910/

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