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

  • SEARCH
  • Home
  • 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 6942471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:01:16+00:00 2026-05-27T13:01:16+00:00

I remember reading a while back that randomly SQL Server can slow down and

  • 0

I remember reading a while back that randomly SQL Server can slow down and / or take a stupidly long time to execute a stored procedure when it is written like:

CREATE PROCEDURE spMyExampleProc
(
   @myParameterINT
)
AS
BEGIN

   SELECT something FROM myTable WHERE myColumn = @myParameter

END

The way to fix this error is to do this:

CREATE PROCEDURE spMyExampleProc
(
   @myParameterINT
)
AS
BEGIN
   DECLARE @newParameter INT
   SET @newParameter = @myParameter

   SELECT something FROM myTable WHERE myColumn = @newParameter 
END

Now my question is firstly is it bad practice to follow the second example for all my stored procedures? This seems like a bug that could be easily prevented with little work, but would there be any drawbacks to doing this and if so why?

When I read about this the problem was that the same proc would take varying times to execute depending on the value in the parameter, if anyone can tell me what this problem is called / why it occurs I would be really grateful, I cant seem to find the link to the post anywhere and it seems like a problem that could occur for our company.

  • 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-27T13:01:17+00:00Added an answer on May 27, 2026 at 1:01 pm
    • The problem is “parameter sniffing” (SO Search)
    • The pattern with @newParameter is called “parameter masking” (also SO Search)

    You could always use the this masking pattern but it isn’t always needed. For example, a simple select by unique key, with no child tables or other filters should behave as expected every time.

    Since SQL Server 2008, you can also use the OPTIMISE FOR UNKNOWN (SO). Also see Alternative to using local variables in a where clause and Experience with when to use OPTIMIZE FOR UNKNOWN

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

Sidebar

Related Questions

I remember reading somewhere that SQL Azure is going to terminate long-running queries. Is
Background: A long time I remember reading about a Java library that was created
I remember reading a while back in regards to logical operators that in the
I'm not terribly familiar with NoSQL systems, but I remember reading a while back
I remember reading somewhere that you can provide your own icons without having them
I remember reading quite a while back about a constructor idiom for C++ in
I remember reading some time ago that there were cpu cards for systems to
I remember reading a while ago that either asynchronous or synchronous resets are more
Long time ago, I was creating a mini ORM using reflection. While reading about
I remember reading a great document a while back explaining the rationale for Git

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.