gpt4 book ai didi

sql-server - 如何在从自身更新同一个表时为表添加别名?

转载 作者:行者123 更新时间:2023-12-04 18:32:14 28 4
gpt4 key购买 nike

如何在从自身更新同一个表时为表添加别名?

我的查询:

update accounts set adusername = x.adusername 
from Accounts x
where x.AccountName = accounts.rev and x.ok>10 and accounts.ok in (0,1,2,3)
and x.ADUserName is not null and accounts.ADUserName is null

错误

Msg 4104, Level 16, State 1, Line 9
The multi-part identifier "accounts.rev" could not be bound.
Msg 4104, Level 16, State 1, Line 9
The multi-part identifier "accounts.ok" could not be bound.
Msg 4104, Level 16, State 1, Line 9
The multi-part identifier "accounts.ok" could not be bound.
Msg 4104, Level 16, State 1, Line 9
The multi-part identifier "accounts.ok" could not be bound.
Msg 4104, Level 16, State 1, Line 9
The multi-part identifier "accounts.ok" could not be bound.
Msg 4104, Level 16, State 1, Line 9
The multi-part identifier "accounts.ADUserName" could not be bound.

最佳答案

这个怎么样:

UPDATE a
SET a.adusername = x.adusername
FROM Accounts x
INNER JOIN Accounts a ON x.AccountName = a.rev
WHERE x.ok>10
AND a.ok in (0,1,2,3)
AND x.ADUserName is not null
AND a.ADUserName is null

关于sql-server - 如何在从自身更新同一个表时为表添加别名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36912594/

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