过程 超过最大存储过程、函数、触发器或视图嵌套级别(限制 32)
存储过程在以下位置失败,谢谢您的帮助。
--Insert MSOrg Information
DECLARE @PersonnelNumber int,
@MSOrg varchar(255)
DECLARE csr CURSOR FAST_FORWARD FOR
SELECT PersonnelNumber FROM Person
OPEN csr
FETCH NEXT FROM csr
INTO @PersonnelNumber
WHILE @@FETCH_STATUS = 0
BEGIN
EXEC GetMSOrg @PersonnelNumber, @MSOrg out
INSERT INTO PersonSubject (
PersonnelNumber
,SubjectID
,SubjectValue
,Created
,Updated
)
SELECT @PersonnelNumber
,SubjectID
,@MSOrg
,getDate()
,getDate()
FROM Subject
WHERE DisplayName = 'MS Org'
FETCH NEXT FROM csr
INTO @PersonnelNumber
END
CLOSE csr
DEALLOCATE csr
下面是存储的 prc 定义 GetMSOrg,在第三个条件下失败
CREATE PROCEDURE [dbo].[GetMSOrg]
(
@PersonnelNumber int
,@OrgTerm varchar(200) out
)
AS
DECLARE @MDRTermID int
,@ReportsToPersonnelNbr int
--Check to see if we have reached the top of the chart
SELECT @ReportsToPersonnelNbr = ReportsToPersonnelNbr
FROM ReportsTo
WHERE PersonnelNumber = @PersonnelNumber
IF (@ReportsToPersonnelNbr IS NULL) --Reached the Top of the Org Ladder
BEGIN
SET @OrgTerm = 'Non-standard rollup'
END
ELSE IF (@PersonnelNumber IN (SELECT PersonnelNumber FROM OrgTermMap))
BEGIN
SELECT @OrgTerm = s.Term
FROM OrgTermMap tm
JOIN Taxonomy..StaticHierarchy s ON tm.OrgTermID = s.TermID
WHERE tm.PersonnelNumber = @PersonnelNumber
END
ELSE
BEGIN
SELECT @MDRTermID = tm.OrgTermID
FROM ReportsTo r
JOIN OrgTermMap tm ON r.ReportsToPersonnelNbr = tm.PersonnelNumber
WHERE r.PersonnelNumber = @PersonnelNumber
IF (@MDRTermID IS NULL)
BEGIN
EXEC GetMSOrg @ReportsToPersonnelNbr, @OrgTerm out
END
ELSE
BEGIN
SELECT @OrgTerm = Term
FROM Taxonomy..StaticHierarchy
WHERE VocabID = 118
AND TermID = @MDRTermID
END
END
GO
The stored proc is failing at below location,Thanks, for all your help.
--Insert MSOrg Information
DECLARE @PersonnelNumber int,
@MSOrg varchar(255)
DECLARE csr CURSOR FAST_FORWARD FOR
SELECT PersonnelNumber FROM Person
OPEN csr
FETCH NEXT FROM csr
INTO @PersonnelNumber
WHILE @@FETCH_STATUS = 0
BEGIN
EXEC GetMSOrg @PersonnelNumber, @MSOrg out
INSERT INTO PersonSubject (
PersonnelNumber
,SubjectID
,SubjectValue
,Created
,Updated
)
SELECT @PersonnelNumber
,SubjectID
,@MSOrg
,getDate()
,getDate()
FROM Subject
WHERE DisplayName = 'MS Org'
FETCH NEXT FROM csr
INTO @PersonnelNumber
END
CLOSE csr
DEALLOCATE csr
Below is the stored prc defination GetMSOrg and fails at third condition
CREATE PROCEDURE [dbo].[GetMSOrg]
(
@PersonnelNumber int
,@OrgTerm varchar(200) out
)
AS
DECLARE @MDRTermID int
,@ReportsToPersonnelNbr int
--Check to see if we have reached the top of the chart
SELECT @ReportsToPersonnelNbr = ReportsToPersonnelNbr
FROM ReportsTo
WHERE PersonnelNumber = @PersonnelNumber
IF (@ReportsToPersonnelNbr IS NULL) --Reached the Top of the Org Ladder
BEGIN
SET @OrgTerm = 'Non-standard rollup'
END
ELSE IF (@PersonnelNumber IN (SELECT PersonnelNumber FROM OrgTermMap))
BEGIN
SELECT @OrgTerm = s.Term
FROM OrgTermMap tm
JOIN Taxonomy..StaticHierarchy s ON tm.OrgTermID = s.TermID
WHERE tm.PersonnelNumber = @PersonnelNumber
END
ELSE
BEGIN
SELECT @MDRTermID = tm.OrgTermID
FROM ReportsTo r
JOIN OrgTermMap tm ON r.ReportsToPersonnelNbr = tm.PersonnelNumber
WHERE r.PersonnelNumber = @PersonnelNumber
IF (@MDRTermID IS NULL)
BEGIN
EXEC GetMSOrg @ReportsToPersonnelNbr, @OrgTerm out
END
ELSE
BEGIN
SELECT @OrgTerm = Term
FROM Taxonomy..StaticHierarchy
WHERE VocabID = 118
AND TermID = @MDRTermID
END
END
GO
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每次调用 EXEC GetMSOrg 都会沿着查询继续进行,
并且当 PersonnelNumber 不再向任何人报告时,有一个退出子句。
因此,唯一合乎逻辑的结论是,你有一个周期性的人->报告对象->..->人。这甚至可以在单个记录上。
此查询将在报告到记录中查找循环:
Each call to
EXEC GetMSOrg
keeps progressing along the queryAnd there is an exit clause when PersonnelNumber no longer reports to anyone.
Therefore the only logical conclusion is that you have a cyclical person->reportsto->..->person. This could even be on a single record.
This query will find loops within the reportsto records: