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 99135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:19:46+00:00 2026-05-11T00:19:46+00:00

Your basic SP with a default parameter: ALTER PROCEDURE [usp_debug_fails] @DATA_DT_ID AS int =

  • 0

Your basic SP with a default parameter:

ALTER PROCEDURE [usp_debug_fails]     @DATA_DT_ID AS int = 20081130 WITH RECOMPILE AS BEGIN     /*         Usage:         EXEC [usp_debug_fails] WITH RECOMPILE     */     -- Stuff here that depends on DATA_DT_ID END 

The same SP with a local that is hardcoded.

ALTER PROCEDURE usp_debug_works] WITH RECOMPILE AS BEGIN     /*         Usage:         EXEC [usp_debug_works] WITH RECOMPILE     */      DECLARE @DATA_DT_ID AS int     SET @DATA_DT_ID = 20081130     -- Stuff here that depends on DATA_DT_ID END 

You can see where I put in the (redundant, even) WITH RECOMPILE options in order to avoid parameter sniffing (this was never necessary in development where this thing worked fine)

The one that works completes fine in a minute or two, the other never completes – just sits there for hours.

This problem never happened on the development server (build 9.00.3282.00), the production server is build 9.00.3068.00

I’ve removed all kinds of code from the procs to try to get down to the minimal version which still exhibits the problem, and have been very careful to keep both versions of the SP the same except for that one parameter.

I have plenty of other SPs which take parameters and they do run fine. I’ve also DROPped and reCREATEed the SPs.

Any ideas?

And yes, I have a DBA looking at it and I do not have SHOWPLAN or any useful rights on production to see if there is blocking (in case one’s plan results in a lock escalation I guess – again, the only difference is the parameter)

I’ve reviewed all the SQL Server build information and don’t see a known issue about this, so until I figure it out or the DBA figures it out, I’m kind of stuck.

UPDATE

This also fails to complete (this is actually the normal form for these SPs – I just put a default in to make it easier to switch back and forth during testing)

ALTER PROCEDURE [usp_debug_fails]     @DATA_DT_ID AS int WITH RECOMPILE AS BEGIN     /*         Usage:         EXEC [usp_debug_fails] 20081130 WITH RECOMPILE     */     -- Stuff here that depends on DATA_DT_ID END 

however this one completes (which may work as a workaround, although I have about 25 of these SPs to modify which all have the same form):

ALTER PROCEDURE [usp_debug_fails]     @DATA_DT_ID_in AS int WITH RECOMPILE AS BEGIN     /*         Usage:         EXEC [usp_debug_fails] 20081130 WITH RECOMPILE     */      DECLARE @DATA_DT_ID AS int     SET @DATA_DT_ID = @DATA_DT_ID_in     -- Stuff here that depends on DATA_DT_ID END 
  • 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. 2026-05-11T00:19:47+00:00Added an answer on May 11, 2026 at 12:19 am

    Try masking the input parameter.

    I guess the recompile isn’t working because of the specified default (EDIT: Or parameter sent on first call) being sniffed at compile time. So, recompile has no effect.

    I’ve seen huge difference between estimated plans simply by changing the default from say, zero to NULL, or not having one.

    ALTER PROCEDURE [usp_debug_mightwork]     @DATA_DT_ID AS int = 20081130 AS BEGIN     DECLARE @IDATA_DT_ID AS int     SET @IDATA_DT_ID = @DATA_DT_ID     -- Stuff here that depends on IDATA_DT_ID END 

    I think this article explains…

    …parameter values are sniffed during compilation or recompilation…

    EDIT:

    New link on query plans and parameters. It’s still parameter sniffing whether a default is specified or not.

    The WITH RECOMPILE option specified on the GetRecentSales stored procedure above does not eliminate the cardinality estimation error

    Kind of related article about constants and plans

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

Sidebar

Ask A Question

Stats

  • Questions 101k
  • Answers 101k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Setting the borderStyle property on the UITextField to UITextBorderStyleNone should… May 11, 2026 at 8:02 pm
  • Editorial Team
    Editorial Team added an answer This works correctly for me. In my AssemblyInfo.cs file, I… May 11, 2026 at 8:02 pm
  • Editorial Team
    Editorial Team added an answer I believe the solution you're looking for is available through… May 11, 2026 at 8:02 pm

Related Questions

I'm trying to move toward TDD, ORM, Mocking, ect. I need a good example
I'm basically trying to figure out the simplest way to perform your basic insert
After the last project I've done using WebForms, I've decided to pass on using
I'm having some trouble with displaying results from a datasource. This code will show

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.