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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Stored Procedure Woes

Author  Topic 

Kuriyama
Starting Member

4 Posts

Posted - 2009-03-06 : 10:16:17
First time posting on this forum, so please go easy on me.

I have a recursive stored procedure that is responsible for building a bread crumb for an individual category id.

CREATE PROCEDURE [dbo].[ctg_getCategoryBreadCrumb] (
@dept_id INT,
@returnValue VARCHAR(1000) OUTPUT
)
AS

DECLARE @rec_parent_id INT
DECLARE @rec_dept_id INT

DECLARE catCursor CURSOR LOCAL FAST_FORWARD

FOR
SELECT parent_id, dept_id FROM cablestogo_dept
WHERE dept_id = @dept_id

OPEN catCursor
FETCH NEXT FROM catCursor INTO @rec_parent_id, @rec_dept_id
CLOSE catCursor
DEALLOCATE catCursor

IF(@rec_parent_id = 0)
set @returnValue = (SELECT dept_name FROM cablestogo_dept WHERE dept_id = @dept_id)
ELSE
BEGIN
EXEC ctg_getCategoryBreadCrumb @rec_parent_id, @returnValue OUTPUT
IF(@returnValue <> '')
set @returnValue = @returnValue + ' > ' + (SELECT dept_name FROM cablestogo_dept where dept_id = @dept_id)
ELSE
set @returnValue = (SELECT dept_name FROM cablestogo_dept where dept_id = @dept_id)
END

RETURN
GO



I also have created a stored procedure that will build breadcrumbs for all products. Products are related to category ids, so one product can have multiple breadcrumbs.



CREATE PROCEDURE [dbo].[ctg_UpdateFroogleFeedBreadCrumb]
AS
DECLARE @curr_sku INT
DECLARE @curr_dept_id INT
DECLARE @return_value VARCHAR(1000)
DECLARE @i INT

SET @i = 0
DECLARE ffCursor CURSOR LOCAL FAST_FORWARD

FOR
SELECT TOP 100 ff.sku, cdp.dept_id FROM froogleFeed1 ff
INNER JOIN cablestogo_dept_prod cdp ON
ff.sku = cdp.sku
INNER JOIN cablestogo_dept cd ON
cdp.dept_id = cd.dept_id
WHERE cd.redirect IS NULL
ORDER BY ff.sku ASC

OPEN ffCursor
FETCH NEXT FROM ffCursor INTO @curr_sku, @curr_dept_id

WHILE @@FETCH_STATUS = 0
BEGIN
EXEC ctg_getCategoryBreadCrumb @curr_dept_id, @return_value OUTPUT
PRINT @return_value
FETCH NEXT FROM ffCursor INTO @curr_sku, @curr_dept_id
SET @return_value = ''
END

Print @i
CLOSE ffCursor
DEALLOCATE ffCursor
GO


There are 8583 records that I need to build breadcrumbs for. This works on small data sets, but when I attempt to run this against large amounts of data I get this error.

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

Any ideas on how to correct this issue?

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2009-03-06 : 11:20:53
1. move away from cursors....(they are really bad news
2. can you post sample input data & matching expected results....read the FAQ section to see howe to post useful information so that we can help you.

3. your problem is not the number of records you are processing...it's the number of time 1 particular record is causing the SP to call itself.

recursive SP's are not a good idea....there usually should be a better way to achieve the same result without recursion. there are some alternatives if you are on SQL2005 or SQL 2008.
Go to Top of Page

Kuriyama
Starting Member

4 Posts

Posted - 2009-03-06 : 13:02:51
quote:
Originally posted by AndrewMurphy

1. move away from cursors....(they are really bad news
2. can you post sample input data & matching expected results....read the FAQ section to see howe to post useful information so that we can help you.

3. your problem is not the number of records you are processing...it's the number of time 1 particular record is causing the SP to call itself.

recursive SP's are not a good idea....there usually should be a better way to achieve the same result without recursion. there are some alternatives if you are on SQL2005 or SQL 2008.



Thank you for the reply AndrewMurphy.

I was able to solve the problem, it was a data issue that was putting my recursive function in an infinite loop. My base case was the issue. I will read the FAQ section and get back to you.

Thanks again.
Go to Top of Page
   

- Advertisement -