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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:22:59+00:00 2026-06-05T05:22:59+00:00

Other that duplicating a query in an sproc, is there any way to specify

  • 0

Other that duplicating a query in an sproc, is there any way to specify a hint based on an sproc parameter? For example, with parameter @waitForLock, if it’s set to 0 I want to use the READPAST hint, otherwise wait/block until the other transaction completes.

  • 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-06-05T05:23:01+00:00Added an answer on June 5, 2026 at 5:23 am

    In general I like the OPTION RECOMPILE suggestion, though that means it will recompile every time, even if stats or your parameter haven’t changed. This is usually to thwart parameter sniffing, not help with cases where you want to avoid or not avoid taking locks.

    One idea is to use dynamic SQL (which can also be beneficial depending on your “optimize for ad hoc workloads” setting and the frequency you run with one parameter or the other).

    CREATE PROCEDURE dbo.whatever
        @waitForLock BIT = 1
    AS
    BEGIN
       SET NOCOUNT ON;
    
       DECLARE @sql NVARCHAR(MAX);
    
       SET @sql = 'SELECT something FROM dbo.somewhere';
    
       IF @waitForLock = 0
          SET @sql = @sql + ' WITH (READPAST)';
    
       SET @sql = ' WHERE <some condition> ...';
    
       EXEC sp_executesql @sql;
    END
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any other method that is faster than doing like this? private void
There are other posts that say you can create a control in windows forms
I know there are other questions that have similar issues, but I have read
I need to write a a query that gets a set of information from
Other than that I don't know if I can reproduce it now that it's
I noticed the other day that I cannot bind variables when using PDO with
I have the following problem that other people must have encountered. I am working
I have looked at many other threads that show how to use accelerometer values,
I saw a blog post the other day that had a screen shot of
I've read through the two other threads that extract the dll from the application

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.