Search

TSQL case statement fails: Internal error: Server stack limit has been reached. (8631) by NigelCook

Active

11
0
Sign in
to vote
Type: Bug
ID: 718795
Opened: 1/16/2012 7:02:57 AM
Access Restriction: Public
0
Workaround(s)
6
User(s) can reproduce this bug
A Long case statement with 1740 cases that used to work on SQL2005 and SQL2008, now fails with :
Msg 8631, Level 17, State 1, Line 7
Internal error: Server stack limit has been reached. Please look for potentially deep nesting in your query, and try to simplify it.
The case has the form:
declare @EnumString varchar(200) = 'string1'
select
case @EnumString
when 'string1' then 1000000
when 'string2' then 1000001
when 'string3' then 1000002
when 'string4' then 1000003
...
end

Is there any chance that this will be fixed before RTM or is this a new limitation to case statements or the number of literals?
Details (expand)

Product Language

English

Version

SQL Server 2012 RC0

Category

SQL Engine

Operating System

Windows 7 (all editions)

Operating System Language

English

Steps to Reproduce

declare @EnumString varchar(200) = 'string1'
select
case @EnumString
when 'string1' then 1000000
when 'string2' then 1000001
when 'string3' then 1000002
when 'string4' then 1000003

/*1736 more whens and thens similar to those above go here, but pasting them in here sent me over the 2000 character limit. */

end

I have attached a file with a complete example in it.

Actual Results

Msg 8631, Level 17, State 1, Line 7
Internal error: Server stack limit has been reached. Please look for potentially deep nesting in your query, and try to simplify it.

Expected Results

1000000

Platform

X64

Virtualization

 
File Attachments
File Name Submitted By Submitted On File Size  
SQL2012 Example of case statement error.sql 1/23/2012 53 KB
Sign in to post a comment.
Posted by Guruprasad V on 6/12/2013 at 12:02 AM
Same here, When I run SQL Statement which has sequence of CASE statements (Search condition), it fails beyond 1329 case

SELECT    CustomerKey,
CASE
WHEN Code='SAP' AND Area='APAC' THEN 'Asia' --1
WHEN Code='SAP' AND Area='Canada' THEN 'NA' --2
.
.
WHEN Code='SAP' AND Area='AUD' THEN 'NA' --1329
END

Msg 8631, Level 17, State 1, Line 6
Internal error: Server stack limit has been reached. Please look for potentially deep nesting in your query, and try to simplify it.
Posted by Nick81 on 12/11/2012 at 9:53 PM
Just to clarify, I would like to mention that in my case, the error showed when executing a stored procedure with 200 arguments. This is a simple SP with an update statement taking in the 200 arguments and using them to update the values of the 200 fields of a single table in our database.

I actually managed to find a temporary fix for this by splitting the update statement into 2 separate update statements. I found out that the "limit" for the number of arguments for a single update statement was of 153/154. Adding just a single argument to this would give the error.
In other terms, the issue was not with the SP call itself but with the update statement. The SP still takes 200 arguments without giving the error.
Posted by Nick81 on 12/11/2012 at 12:46 AM
This issue was first reported back in January and now, testing the same case on SP1 CU#1 returns the same error message...

Is there any way at all to give some priority to this issue? I am sure I am not the only one who'd be glad to get some feedback from Microsoft on this.

Searching the internet for similar cases returns nothing. This is the one page with people reporting it...
Posted by Janet Esposito on 11/29/2012 at 11:37 AM
Here's a new wrinkle on this problem.

I have one procedure where the creation script will run fine on some computers using SQl Server 2012 but we get the server stack limit error on others. It's only 450 lines but does contain a few dynamic sql statements.

My desktop computer is a 64-bit machine and laptop is 32-bit. It runs fine on the 64-bit machine but fails on the 32-bit machine. Both machines can create it just fine under SQL Server 2008.
Posted by Nick81 on 10/22/2012 at 1:45 AM
We're facing the same issue as well. Did anyone find a workaround or a fix which doesn't require to rewrite the stored procedures completely... ?
Posted by Serg2121 on 10/12/2012 at 11:29 AM
I'm getting the same error, is any solution at this time?

This is a big problem, beacuse I'm migrating a lot of stored procedures and some of them has nested case statements.

I hope you can help us with this issue.
Posted by Chris DW on 8/9/2012 at 6:11 AM
SQL Server 2012 (11.0.2100)

I'm seeing this on a view with case statements that calls a complex function with a large case statement, the function if called directly does not give this error. This is preventing us from adopting SQL Server 2012
Posted by NewVision1 on 1/26/2012 at 2:56 AM
SQL Server 2012 (Denali)

I retrive the same error (Msg 8631 - Server stack limit has been reached...) in case of executing of stored procedure with 1024 params. I don't meet the error with SQL 2008.

EXECUTE @RC = [DB1].[dbo].[TestDenali20121]
@P0=1,
@P1=1,
@P2=1,
@P3=1,
...
@P1023=1,
@POUT = @POUT OUTPUT

SELECT    @POUT as N'@POUT'
Posted by Microsoft on 1/23/2012 at 3:19 PM
Hello Nigel,
Thanks for reporting the issue. We will invetigate and let you know what we find.

--
Umachandar, SQL Programmability Team
Sign in to post a workaround.