Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-01-03
3
Medium Priority
?
4,967 Views
Last Modified: 2014-01-03
I have an cursor, it always gave nested errors where as we have on 5 subjects for B.Com and semester 1

alter procedure step1
@course varchar(200),
@semester int
as
begin
declare @tsubjectcode varchar(200)
declare @tcredits varchar(200)
declare db_step1 cursor for
select distinct subjectcode,credits from allsubjects
where course=@course and semester=@semester
order by 1
open db_step1
fetch next from db_step1 into @tsubjectcode,@tcredits
while @@fetch_status=0
begin
      select @tsubjectcode,@tcredits
fetch next from db_step1 into @tsubjectcode,@tcredits
end
close db_step1
deallocate db_step1
end

exec step1 'B.Com',1
0
Comment
Question by:searchsanjaysharma
3 Comments
 
LVL 22

Expert Comment

by:plusone3055
ID: 39754939
thats for nesting
Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32).

this means that something that you are drawing information from in your stored procedure is more than 32  nested levels deep. Its obvoiusly not in the code above. You'll have to dig to find that elsewhere in one of your other functions thats your using in this SP.
0
 
LVL 25

Accepted Solution

by:
DBAduck - Ben Miller earned 2000 total points
ID: 39755001
The reason is that you have exec step1 'B.Com', 1 in a line that will be part of the stored procedure.

So when you execute step1 you will be executing it and it will execute itself again while in the proc.

You need to put a GO between the end and the exec

alter procedure step1
@course varchar(200),
@semester int
as
begin
declare @tsubjectcode varchar(200)
declare @tcredits varchar(200)
declare db_step1 cursor for 
select distinct subjectcode,credits from allsubjects 
where course=@course and semester=@semester
order by 1
open db_step1
fetch next from db_step1 into @tsubjectcode,@tcredits
while @@fetch_status=0
begin
      select @tsubjectcode,@tcredits
fetch next from db_step1 into @tsubjectcode,@tcredits
end
close db_step1
deallocate db_step1
end 

GO

exec step1 'B.Com',1

Open in new window

0
 

Author Closing Comment

by:searchsanjaysharma
ID: 39755217
tx
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question