hi all,
i have the following recursive function but i keep on getting the error
Server: Msg 217, Level 16, State 1, Procedure GetReports, Line 31
Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32).
I have tried putting in a count on this but i still get the error.
Here is the function. Would appreciate any suggestions!
CREATE FUNCTION dbo.GetReports(@IncludeParent bit, @intParentPlantAreaID int)
RETURNS @retFindReports TABLE (intParentPlantAreaID int, strPlantAreaName varchar(50), intPlantAreaID int)
AS
BEGIN
IF (@IncludeParent=1)
BEGIN
INSERT INTO @retFindReports
SELECT intParentPlantAreaID, strPlantAreaName , intPlantAreaID FROM tblSafeTrackIT_Config_Area WHERE intParentPlantAreaID=-@intParentPlantAreaID
END
DECLARE @Report_ID int, @Report_strPlantAreaName varchar(50), @Report_intPlantAreaID int, @Count varchar(2)
SET @Count = '1'
DECLARE RetrieveReports CURSOR STATIC LOCAL FOR
SELECT intParentPlantAreaID, strPlantAreaName , intPlantAreaID FROM tblSafeTrackIT_Config_Area WHERE intPlantAreaID=@intParentPlantAreaID
OPEN RetrieveReports
FETCH NEXT FROM RetrieveReports
INTO @Report_ID, @Report_strPlantAreaName, @Report_intPlantAreaID
WHILE @Count <= 32
WHILE (@@FETCH_STATUS = 0)
BEGIN
INSERT INTO @retFindReports
SELECT * FROM dbo.GetReports(0,@Report_ID)
INSERT INTO @retFindReports
VALUES(@Report_ID,@Report_strPlantAreaName, @Report_intPlantAreaID)
FETCH NEXT FROM RetrieveReports
INTO @Report_ID, @Report_strPlantAreaName, @Report_intPlantAreaID
SET @Count = @Count + 1
END
CLOSE RetrieveReports
DEALLOCATE RetrieveReports
RETURN
END
i have the following recursive function but i keep on getting the error
Server: Msg 217, Level 16, State 1, Procedure GetReports, Line 31
Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32).
I have tried putting in a count on this but i still get the error.
Here is the function. Would appreciate any suggestions!
CREATE FUNCTION dbo.GetReports(@IncludeParent bit, @intParentPlantAreaID int)
RETURNS @retFindReports TABLE (intParentPlantAreaID int, strPlantAreaName varchar(50), intPlantAreaID int)
AS
BEGIN
IF (@IncludeParent=1)
BEGIN
INSERT INTO @retFindReports
SELECT intParentPlantAreaID, strPlantAreaName , intPlantAreaID FROM tblSafeTrackIT_Config_Area WHERE intParentPlantAreaID=-@intParentPlantAreaID
END
DECLARE @Report_ID int, @Report_strPlantAreaName varchar(50), @Report_intPlantAreaID int, @Count varchar(2)
SET @Count = '1'
DECLARE RetrieveReports CURSOR STATIC LOCAL FOR
SELECT intParentPlantAreaID, strPlantAreaName , intPlantAreaID FROM tblSafeTrackIT_Config_Area WHERE intPlantAreaID=@intParentPlantAreaID
OPEN RetrieveReports
FETCH NEXT FROM RetrieveReports
INTO @Report_ID, @Report_strPlantAreaName, @Report_intPlantAreaID
WHILE @Count <= 32
WHILE (@@FETCH_STATUS = 0)
BEGIN
INSERT INTO @retFindReports
SELECT * FROM dbo.GetReports(0,@Report_ID)
INSERT INTO @retFindReports
VALUES(@Report_ID,@Report_strPlantAreaName, @Report_intPlantAreaID)
FETCH NEXT FROM RetrieveReports
INTO @Report_ID, @Report_strPlantAreaName, @Report_intPlantAreaID
SET @Count = @Count + 1
END
CLOSE RetrieveReports
DEALLOCATE RetrieveReports
RETURN
END