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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Maximum stored procedure

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 error

Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)

if i remove this row it will run no problem

What am i missing?

X002548
Not Just a Number

15586 Posts

Posted - 2009-11-05 : 10:35:23
post the sprocs...but it sounds like your looping calls



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

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 fine


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO




ALTER 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) OUTPUT
AS


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


Go to Top of Page

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 one

Not that I can explain it...but it does seem the "nested" call of the sproc in the loop is having a problem

Could be wrong, however, it wouldn't appear so

Please post the sproc del_hrs_actual_0506




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

pmccann1
Posting Yak Master

107 Posts

Posted - 2009-11-05 : 10:53:47
that is the del_hrs_actual_0506 it calls its self
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-11-05 : 13:06:01
it calls itself?

for the love of.....

Did you write this?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-11-05 : 13:10:44
Wait,

You Declare @TempTable

Then INSERT INTO TempTable

Do you have a permanent table called TempTable as well?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

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 grouping

it 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 select



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

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
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-11-05 : 13:43:10
you have our sympathies...a sproc that calls itself, inside of a cursor

I have to admit, this is a first

I'm looking



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

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 itself

Sorry chief, but this is a mess, unreliable, and dangerous

Did 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 follow

Give us as much info (background) as you can, and let us know if you are on the hook to debug it

Also, find out the name of the person who wrote it



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-11-05 : 13:57:36
oH, THIS ONE IS CUTE

[CODE]
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

[/CODE]

You wouldn't be TJ would you?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

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 original


ALTER 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) OUTPUT
AS

BEGIN
DECLARE @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 exec
DECLARE @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_week

DECLARE 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 = 1

OPEN RetrieveAOS
FETCH NEXT FROM RetrieveAOS
INTO @lnk_aos_code, @lnk_acad_period, @lnk_aos_period

WHILE (@@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
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




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

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
Go to Top of Page
   

- Advertisement -