我正在使用SQL Server对即使在表中由UPDATE触发的内容进行编程。
所以结构就像:在触发器中,我有:
EXEC StoredProcedure1
在StoredProcedure1
我有:
INSERT dbo.UnbalancedFreqStops
SELECT APremise AS PremiseID
,geography::ConvexHullAggregate(Location) AS Shape
FROM
(SELECT
A.[Premise ID] AS APremise, B.[Premise ID] AS BPremise,
B.LatLon AS Location, B.[Service Frequency] AS FreqT, B.Mon_Routed AS MonT,
B.Tue_Routed AS TueT, B.Wed_Routed AS WedT, B.Thu_Routed AS ThuT,
B.Fri_Routed AS FriT, B.Sat_Routed AS SatT, B.Sun_Routed AS SunT
FROM
dbo.Weekly AS A
INNER JOIN
dbo.Weekly AS B ON A.LatLon.STDistance(B.LatLon) <= (80 * 2)
) AS Clusters
GROUP BY
APremise
HAVING
MAX(FreqT) <> (MAX(MonT) + MAX(TueT) + MAX(WedT) + MAX(ThuT) + MAX(FriT) + MAX(SatT) + MAX(SunT));
有趣的是,只有当我从触发器调用存储过程时,它才会因违反主键错误(PremiseId
是唯一PK)而出错。如果我(1)单独运行它,或者(2)从另一个存储过程调用它,则存储过程运行正常。
此外,我单独运行查询,发现没有重复的密钥AT ALL。
有人可以启发我吗?
谢谢!