我尝试按以下方式进行更新:
UPDATE a
SET a.PackageID = p.ID
FROM gym.Account a
JOIN Packages p
ON a.MembershipTypeID = p.MembershipTypeID
and a.SiteID = p.SiteID
and a.SiteID = 1
我收到错误消息
子查询返回的值超过1个
我不知道这条错误信息是如何准确的,因为当我查询时:
select
ID, SiteID, PackageName, MembershipTypeID
from
Packages
where
siteid = 1
order by
MembershipTypeID, PackageName
... MembershipTypeID
值都是唯一的 - 没有重复!
然后我看了Stack question here,并尝试了这个:
UPDATE gym.Account
SET PackageID = (SELECT top 1 ID
FROM Packages
WHERE gym.Account.MembershipTypeID = MembershipTypeID)
然而,我仍然得到相同的错误信息,即使我正在做一个TOP 1.如何解决这个问题?
答案 0 :(得分:4)
检查表格上是否有触发器。这可能是你错误的根源。
:)