在 Update 语句中使用子查询
我在删除时触发的触发器中有以下 SQL 语句:
UPDATE bk2_InfoPages
SET SortOrder = SortOrder - (SELECT COUNT(*) FROM Deleted d WHERE d.SortOrder <= SortOrder)
我的问题是最后一个 SortOrder
引用了 Deleted
表,而不是 bk2_InfoPages< /代码>表。 我不允许向
bk2_InfoPages
表添加别名,因为它是一个 UPDATE
语句 - 那么我应该怎么做?
I have the following SQL statement in a trigger that fires on deletion:
UPDATE bk2_InfoPages
SET SortOrder = SortOrder - (SELECT COUNT(*) FROM Deleted d WHERE d.SortOrder <= SortOrder)
My problem is that the very last SortOrder
refers to the Deleted
table and not to the bk2_InfoPages
table. I am not allowed to add an alias to the bk2_InfoPages
table because it's an UPDATE
statement - so what should I do instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这应该可行:
您必须为表添加别名才能执行子查询,例如:
This should work:
You have to alias your table to do sub queries, for example:
希望这会起作用!
Hope this would work!