Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6103807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:46:14+00:00 2026-05-23T13:46:14+00:00

Running SQL 2005 X64. First, create the following stored proc on a database: CREATE

  • 0

Running SQL 2005 X64.

First, create the following stored proc on a database:

CREATE PROCEDURE dbo.Test 
    @Value int = null

AS

BEGIN

    IF (IsNull(@Value, '') = '')
        SELECT '*I am NULL!*'
    ELSE
        SELECT 'I am ' + CONVERT(varchar(20), @Value)

END

Try executing the above proc as follows, and you get the result below:

EXEC dbo.Test

I am NULL!

Now, ALTER the proc so that the EXEC statement is part of the sproc itself:

ALTER PROCEDURE dbo.Test 
    @Value int = null

AS

BEGIN

    IF (IsNull(@Value, '') = '')
        SELECT 'I am NULL!'
    ELSE
        SELECT 'I am ' + CONVERT(varchar(20), @Value)

END

EXEC dbo.Test

If you execute it now, you get…

I am NULL!

I am NULL!

I am NULL!

…ad infinitum until the output breaks with this error:

Msg 217, Level 16, State 1, Procedure
Test, Line 16 Maximum stored
procedure, function, trigger, or view
nesting level exceeded (limit 32).

Ignoring for the moment that this isn’t at all a standard practice and that most likely someone would do something like this only by accident, could someone please provide some low-level insight on what SQL 2005 is “thinking” when the second incarnation of this proc is executed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:46:15+00:00Added an answer on May 23, 2026 at 1:46 pm

    Your code is behaving as expected. The procedure is calling itself recursively.

    If you do not want that, try this:

    ALTER PROCEDURE dbo.Test 
        @Value int = null
    
    AS
    
    BEGIN
    
        IF (IsNull(@Value, '') = '')
            SELECT 'I am NULL!'
        ELSE
            SELECT 'I am ' + CONVERT(varchar(20), @Value)
    
    END
    
    GO
    
    EXEC dbo.Test
    

    If you do want to use recursion, you have to define a base case (AKA “exit condition”) which will make stored procedure exit the recursion stack.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very long-running stored procedure in SQL Server 2005 that I'm trying
I'm running Windows Server 2003 x64 with 8GB RAM and SQL Server 2005 64
I have a database running on MS SQL Server 2005 and an ASP.NET 3.5
First off let me say I am running on SQL Server 2005 so I
We're running our application's database on dedicated box running only SQL Server 2005. This
I have a SQL DTS package running on a SQL Server 2005 database that,
We're running SQL 2005 standard SP2 on a 4cpu box. Suddenly it crashdumps, after
I have been running SQL Server 2005 Express Management Studio (SSMSE), and I now
We have a Windows machine running SQL Server 2005, and we need to be
We've got a web system running SQL Server 2005 for the back end, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.