gpt4 book ai didi

SQL Server : Update, 设置了另一个选择中的值

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

我有以下查询:

    update UpdCmmPartnerArticleGroup 
set IsActive = 1,
Name = a.GroupName
from
(
select t.Name as GroupName
from @ArticleGroupsTable t
left join UpdCmmPartnerArticleGroup s on s.PartnerID=t.PartnerID and s.Name=t.Name
where s.PartnerID is null
) a
where Name = '' and IsActive = 0

它的目的是获取 GroupNames 列表并将它们分配给 UpdCmmPartnerArticleGroup.Name 字段。该列表有 8 个值,它只使用第一个和最后一个来更新。

我做错了什么,它看起来很简单,但它的行为很奇怪。

最佳答案

您可以使用稍微简化的版本。

UPDATE u
SET IsActive = 1, Name = t.Name
FROM @ArticleGroupsTable t
LEFT JOIN UpdCmmPartnerArticleGroup u
ON u.PartnerID=t.PartnerID AND u.Name=t.Name
WHERE u.Name = '' and u.IsActive = 0 and u.PartnerID IS NULL

关于SQL Server : Update, 设置了另一个选择中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39206840/

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