April 1, 2010 at 1:19 pm
In one database (DB2RWDATA) is an existing (and working) SP that I need moved to a new database; I used Script Stored Procedure As and CREATE To New Query window. In front of each table reference I added DB2RWDATA.dbo to reference tables in the first database, and ran that script in the new database.
Running the SP from the new database returns the correct data, but it keeps running until I get:
Msg 217, Level 16, State 1, Procedure spAchDetails, Line 55
Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32).
The Results tab shows 32 separate result sets all with the same data, and the messages tab keeps "(1 row(s) affected)" several dozen times (interestingly it's a lot more than the number of result sets).
The SP doesn't call any other SPs (and certainly not itself); the only functions used are built in functions (STUFF, RIGHT, RTRIM, and ISNULL). It still works fine in the original location. I also tried deleting the original SP in DB2RWDATA and ran the same CREATE PROCEDURE script in the original DB, so now it has the DB2RWDATA.dbo in front of all the tables; running the new version of the SP from DB2RWDATA shows one resultset as expected...
How can I go about figuring out why the new database is treating it as nested when it's really not?
April 1, 2010 at 1:25 pm
Post your proc here. we can't debug what we can't see. 😀
AND
Read this ...
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgApril 1, 2010 at 1:33 pm
Is there a trigger on the table in the new database that might be recursively calling itself based on data being manipulated?
April 1, 2010 at 1:34 pm
I deleted the SP from the new db and recreated it; now it's working.
In order to test, I added "exec sp" to the end of the query window... I think what happened was when I created the SP in the new location that I didn't highlight just the CREATE PROCEDURE part, so the entire script including the exec became part of the SP... Apparently the entire query window becomes the SP and doesn't stop at the END; statement at the end of the CREATE PROCEDURE... I didn't realize it would do that. Learned something new!
April 1, 2010 at 1:36 pm
Yep, the batch continues on until it hits a 'GO' statement
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgApril 1, 2010 at 1:42 pm
chrismat (4/1/2010)
I deleted the SP from the new db and recreated it; now it's working.In order to test, I added "exec sp" to the end of the query window... I think what happened was when I created the SP in the new location that I didn't highlight just the CREATE PROCEDURE part, so the entire script including the exec became part of the SP... Apparently the entire query window becomes the SP and doesn't stop at the END; statement at the end of the CREATE PROCEDURE... I didn't realize it would do that. Learned something new!
Congrats on finding the issue.
This would be a nice example of a bad loop.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
April 1, 2010 at 2:34 pm
CirquedeSQLeil (4/1/2010)
Congrats on finding the issue.This would be a nice example of a bad loop.
Bad loop indeed. Hmm, what would be a good loop? :w00t:
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
April 1, 2010 at 2:46 pm
WayneS (4/1/2010)
CirquedeSQLeil (4/1/2010)
Congrats on finding the issue.This would be a nice example of a bad loop.
Bad loop indeed. Hmm, what would be a good loop? :w00t:
A hoola hoop.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
April 1, 2010 at 3:20 pm
WayneS (4/1/2010)
CirquedeSQLeil (4/1/2010)
Congrats on finding the issue.This would be a nice example of a bad loop.
Bad loop indeed. Hmm, what would be a good loop? :w00t:
Recursion to the fridg for the next beer.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 2, 2010 at 5:21 am
chrismat (4/1/2010)[hrApparently the entire query window becomes the SP and doesn't stop at the END; statement at the end of the CREATE PROCEDURE... I didn't realize it would do that. Learned something new!
This is something I have seen a lot. The number of procedures that have GRANT statements tacked on the end...:laugh: The key, as Jason says, is to get in the habit of appending a batch terminator to your CREATE/ALTER statements.
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
April 2, 2010 at 8:21 am
Paul White NZ (4/2/2010)
chrismat (4/1/2010)[hrApparently the entire query window becomes the SP and doesn't stop at the END; statement at the end of the CREATE PROCEDURE... I didn't realize it would do that. Learned something new!
This is something I have seen a lot. The number of procedures that have GRANT statements tacked on the end...:laugh: The key, as Jason says, is to get in the habit of appending a batch terminator to your CREATE/ALTER statements.
Coincidentally, I have seen this occur a lot too (GRANT)
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
April 2, 2010 at 8:24 am
I caught trigger definitions in one once 🙂
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply