Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
pmccann1
Posting Yak Master
107 Posts |
Posted - 2009-11-05 : 09:48:07
|
| Sorry to bother you all i am very confused. I have a stored procedure that calls another stored procedure it runs fine until row 1278 is produce then it stop giving the following errorMaximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)if i remove this row it will run no problemWhat am i missing? |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
pmccann1
Posting Yak Master
107 Posts |
Posted - 2009-11-05 : 10:40:57
|
| here is the storperocedure it fails on, if i comment out the call to this procedure everything is fineSET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER OFFGOALTER PROCEDURE [dbo].[del_hrs_actual_0506] @p_acad_period nvarchar (5),@aos_code nvarchar (11), @aos_period nvarchar (5), @TableName nvarchar(10), @claim_period tinyint, @hrs_actual decimal(18,2) OUTPUTAS BEGIN DECLARE @Hours decimal(18,2)DECLARE @TempHours decimal(18,2)DECLARE @RegisterId varchar(7)DECLARE @RegisterGroup varchar(5)DECLARE @TempTable TABLE (register_id char(7), register_group char(5), hrs decimal(18,2)) INSERT INTO TempTable SELECT DISTINCT sttrgprf.register_id, sttrgprf.register_group, SUM((CAST(DATEDIFF(MI, ISNULL(sttrgprf.start_time, 0.00), ISNULL(sttrgprf.end_time, 0.00)) AS decimal) / 60) * (CAST(ISNULL(sttrgprf.end_week,0.00) AS DECIMAL) - CAST(ISNULL(sttrgprf.start_week,0.00) AS DECIMAL) + 1)) AS Hrs, sttrgprf.start_week, sttrgprf.end_week FROM sttrgaos INNER JOIN sttrgprf ON sttrgaos.acad_period = sttrgprf.acad_period AND sttrgaos.register_id = sttrgprf.register_id AND sttrgaos.register_group = sttrgprf.register_group WHERE (sttrgaos.acad_period = @p_acad_period) and (sttrgaos.raoscd_link = @aos_code) and (sttrgaos.rprocd_link = @aos_period) --GROUP BY dbo.sttrgaos.acad_period,sttrgprf.register_id, sttrgprf.register_group GROUP BY dbo.sttrgaos.acad_period, sttrgprf.register_id, sttrgprf.register_group, sttrgaos.raoscd_link, sttrgaos.rprocd_link, sttrgaos.aos_code, sttrgaos.aos_period, --TJ sttrgprf.start_week, sttrgprf.end_week -- 22.08 HF2 DECLARE @root_hrs as DECIMAL(18,2) DECLARE @lnk_acad_period as char(5) DECLARE @lnk_aos_code as char(11) DECLARE @lnk_aos_period as char(5) DECLARE RetrieveAOS CURSOR STATIC LOCAL FOR SELECT stclvlnk.aoscd_link, stclvlnk.lnk_period, stclvlnk.lnk_aos_period FROM stclvlnk LEFT OUTER JOIN stcfesdt ON stclvlnk.aoscd_link = stcfesdt.aos_code AND stclvlnk.lnk_period = stcfesdt.acad_period AND stclvlnk.lnk_aos_period = stcfesdt.aos_period WHERE (stcfesdt.qual_aim IS NULL or stcfesdt.qual_aim = '') AND (stclvlnk.acad_period = @p_acad_period) AND (stclvlnk.aos_code = @aos_code) AND (stclvlnk.aos_period = @aos_period) OPEN RetrieveAOS FETCH NEXT FROM RetrieveAOS INTO @lnk_aos_code, @lnk_acad_period, @lnk_aos_period WHILE (@@FETCH_STATUS = 0) BEGIN exec dbo.del_hrs_actual_0506 @lnk_acad_period,@lnk_aos_code,@lnk_aos_period, @TableName, @claim_period, @hrs_actual OUTPUT FETCH NEXT FROM RetrieveAOS INTO @lnk_aos_code, @lnk_acad_period, @lnk_aos_period END CLOSE RetrieveAOS DEALLOCATE RetrieveAOS Set @hrs_actual = (select coalesce(sum(hrs),0) from (select distinct register_id, register_group, hrs, start_week, end_week from temptable) as hours) --TJ 22.08 HF2 If Upper(@TableName) = 'DELESFUND' update delesfund set hours_actual = @hrs_actual where claim_acad_period = @p_acad_period and claim_period = @claim_period and aos_code = @aos_code and aos_period = @aos_period END |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2009-11-05 : 10:46:01
|
| we have a winner Johhny tell him what's he's oneNot that I can explain it...but it does seem the "nested" call of the sproc in the loop is having a problemCould be wrong, however, it wouldn't appear soPlease post the sproc del_hrs_actual_0506Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
pmccann1
Posting Yak Master
107 Posts |
Posted - 2009-11-05 : 10:53:47
|
| that is the del_hrs_actual_0506 it calls its self |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2009-11-05 : 13:18:39
|
does this part actually work? SELECT DISTINCT sttrgprf.register_id , sttrgprf.register_group , SUM((CAST(DATEDIFF(MI , ISNULL(sttrgprf.start_time, 0.00) , ISNULL(sttrgprf.end_time, 0.00)) AS decimal) / 60) * (CAST(ISNULL(sttrgprf.end_week,0.00) AS DECIMAL) - CAST(ISNULL(sttrgprf.start_week,0.00) AS DECIMAL) + 1)) AS Hrs , sttrgprf.start_week , sttrgprf.end_week FROM sttrgaos INNER JOIN sttrgprf ON sttrgaos.acad_period = sttrgprf.acad_period AND sttrgaos.register_id = sttrgprf.register_id AND sttrgaos.register_group = sttrgprf.register_group WHERE (sttrgaos.acad_period = @p_acad_period) and (sttrgaos.raoscd_link = @aos_code) and (sttrgaos.rprocd_link = @aos_period) GROUP BY dbo.sttrgaos.acad_period , sttrgprf.register_id , sttrgprf.register_group , sttrgaos.raoscd_link , sttrgaos.rprocd_link , sttrgaos.aos_code , sttrgaos.aos_period , sttrgprf.start_week , sttrgprf.end_week maybe it does, but it doesn't make sense with the groupingit wouldn't work in DB2 I know for sure...but the again, there was never a reason for me to do a grouping larger than the selectBrett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
pmccann1
Posting Yak Master
107 Posts |
Posted - 2009-11-05 : 13:39:02
|
| no i did not write this i have inherited this stuff and dont understand why or how it does what it does by returning rows then on certain occasions falls over |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2009-11-05 : 13:54:59
|
| so the "goal" is to get hrs_actual from the call of itself....then to do an update at the end....which it would be doing as it called itselfSorry chief, but this is a mess, unreliable, and dangerousDid you say you worked for a hospital? On wall Street?Let us know<holds in laughter>Is the a spec of what this is suppose to be doing</holds in laughter>Cause I can tell you wright now, no one has tested or audited this process...know why? Because you couldn't write a test plan that anyone could followGive us as much info (background) as you can, and let us know if you are on the hook to debug itAlso, find out the name of the person who wrote itBrett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2009-11-05 : 14:11:35
|
hey...I put some debugging in the code and formatted this mess...Change the name some you don't lose the valuable originalALTER PROCEDURE [dbo].[del_hrs_actual_0506] @p_acad_period nvarchar (5) , @aos_code nvarchar (11) , @aos_period nvarchar (5) , @TableName nvarchar(10) , @claim_period tinyint , @hrs_actual decimal(18,2) OUTPUTASBEGINDECLARE @Hours decimal(18,2), @TempHours decimal(18,2), @RegisterId varchar(7), @RegisterGroup varchar(5), @root_hrs DECIMAL(18,2), @lnk_acad_period char(5), @lnk_aos_code char(11), @lnk_aos_period char(5)--X002548--Lets check the return of the sproc execDECLARE @rc int, @n = 0--this is not used--DECLARE @TempTable TABLE(register_id char(7),register_group char(5),hrs decimal(18,2))INSERT INTO TempTable -- (Should always supply a column list) SELECT DISTINCT sttrgprf.register_id , sttrgprf.register_group , SUM((CAST(DATEDIFF(MI , ISNULL(sttrgprf.start_time, 0.00) , ISNULL(sttrgprf.end_time, 0.00)) AS decimal) / 60) * (CAST(ISNULL(sttrgprf.end_week,0.00) AS DECIMAL) - CAST(ISNULL(sttrgprf.start_week,0.00) AS DECIMAL) + 1)) AS Hrs , sttrgprf.start_week , sttrgprf.end_week FROM sttrgaos INNER JOIN sttrgprf ON sttrgaos.acad_period = sttrgprf.acad_period AND sttrgaos.register_id = sttrgprf.register_id AND sttrgaos.register_group = sttrgprf.register_group WHERE (sttrgaos.acad_period = @p_acad_period) and (sttrgaos.raoscd_link = @aos_code) and (sttrgaos.rprocd_link = @aos_period) GROUP BY dbo.sttrgaos.acad_period , sttrgprf.register_id , sttrgprf.register_group , sttrgaos.raoscd_link , sttrgaos.rprocd_link , sttrgaos.aos_code , sttrgaos.aos_period , sttrgprf.start_week , sttrgprf.end_weekDECLARE RetrieveAOS CURSOR STATIC LOCAL FOR SELECT stclvlnk.aoscd_link , stclvlnk.lnk_period , stclvlnk.lnk_aos_period FROM stclvlnk LEFT JOIN stcfesdt ON stclvlnk.aoscd_link = stcfesdt.aos_code AND stclvlnk.lnk_period = stcfesdt.acad_period AND stclvlnk.lnk_aos_period = stcfesdt.aos_period WHERE (stcfesdt.qual_aim IS NULL or stcfesdt.qual_aim = '') AND (stclvlnk.acad_period = @p_acad_period) AND (stclvlnk.aos_code = @aos_code) AND (stclvlnk.aos_period = @aos_period)SELECT @rc = 0, @n = 1OPEN RetrieveAOSFETCH NEXT FROM RetrieveAOSINTO @lnk_aos_code, @lnk_acad_period, @lnk_aos_periodWHILE (@@FETCH_STATUS = 0) BEGIN exec @rc = dbo.del_hrs_actual_0506 @lnk_acad_period,@lnk_aos_code,@lnk_aos_period, @TableName, @claim_period, @hrs_actual OUTPUT SELECT 'Loop: '+CONVERT(varchar(5),@n) +' Return Code: ' +CONVERT(varchar(5),@rc) +' @hrs_actual: ' +CONVERT(varchar(5),@hrs_actual) SET @n = @n + 1 FETCH NEXT FROM RetrieveAOS INTO @lnk_aos_code, @lnk_acad_period, @lnk_aos_period ENDCLOSE RetrieveAOSDEALLOCATE RetrieveAOSSet @hrs_actual = (select coalesce(sum(hrs),0) from (select distinct register_id, register_group, hrs, start_week, end_week from temptable) as hours) --TJ 22.08 HF2If Upper(@TableName) = 'DELESFUND' update delesfund set hours_actual = @hrs_actual where claim_acad_period = @p_acad_period and claim_period = @claim_period and aos_code = @aos_code and aos_period = @aos_periodEND Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
pmccann1
Posting Yak Master
107 Posts |
Posted - 2009-11-05 : 16:42:17
|
| this code was paid for and was supposed to be done by professionals, it has confused life out of me. inheriting code is never good. thank you all for your help, hope to get to bottom of it all |
 |
|
|
|
|
|
|
|