更新 SQL Server 中的列触发器 - 错误多部分标识符无法绑定

发布于 2024-10-01 01:07:47 字数 543 浏览 5 评论 0原文

我正在尝试找到正确的语法来创建简单的更新触发器。

我始终收到错误消息

无法绑定多部分标识符“AD.AgencyId”。

这是触发器,AgencyDivision 的 [FullName] 列也应包含其父级(代理机构)名称[机构].名称。

CREATE TRIGGER [dbo].[trUpdateAgencyDivisionFullName] 
ON [dbo].[AgencyDivision] FOR UPDATE, INSERT
AS

BEGIN
    UPDATE AD
    SET AD.FullName = A.Name + ' , ' + AD.DivisionName
    FROM AgencyDivision as AD, inserted AS i
    JOIN Agency AS A
    ON AD.AgencyId = A.Id
    WHERE i.Id = AD.Id
END

我可以进行任何语法更改来解决这个问题吗?这个 JOIN 结构可以在触发器中工作吗?谢谢。

I am trying to find the correct syntax to create a simple update trigger.

I consistently get the error message

The multi-part identifier "AD.AgencyId" could not be bound.

Here is the trigger, The [FullName] column of AgencyDivision should contain it's parent's (Agency) Name as well [Agency].Name.

CREATE TRIGGER [dbo].[trUpdateAgencyDivisionFullName] 
ON [dbo].[AgencyDivision] FOR UPDATE, INSERT
AS

BEGIN
    UPDATE AD
    SET AD.FullName = A.Name + ' , ' + AD.DivisionName
    FROM AgencyDivision as AD, inserted AS i
    JOIN Agency AS A
    ON AD.AgencyId = A.Id
    WHERE i.Id = AD.Id
END

Are there any syntax changes I can make to solve this? Can this JOIN structure work in triggers? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独患者 2024-10-08 01:07:47

听起来太明显了,但是您可以仔细检查 AgencyDivision 表上是否有 AgencyId 吗?

另外,仅从纯粹的语法角度来看,我会将其更改为:

UPDATE AD 
SET AD.FullName = A.Name + ' , ' + AD.DivisionName 
FROM AgencyDivision as AD
INNER JOIN inserted AS i ON i.Id = AD.Id 
INNER JOIN Agency AS A ON AD.AgencyId = A.Id 

在您的版本中,您正在混合 ANSI 和 theta 语法进行连接。

It sounds too obvious, but can you double check that the AgencyDivision table has an AgencyId on it?

Also, just from a pure syntax perspective, I would change it to:

UPDATE AD 
SET AD.FullName = A.Name + ' , ' + AD.DivisionName 
FROM AgencyDivision as AD
INNER JOIN inserted AS i ON i.Id = AD.Id 
INNER JOIN Agency AS A ON AD.AgencyId = A.Id 

In your version, you are mixing ANSI and theta syntax for your joins.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文