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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:52:58+00:00 2026-05-30T03:52:58+00:00

I have a view that joins SQL Server tables on linked servers. There are

  • 0

I have a view that joins SQL Server tables on linked servers. There are certain restrictions on linked servers that mean I can’t create an index on the view and there is a stored procedure that last night locked the database, even though it is only doing a select. The stored procedure is generated by .NetTiers (I’ve elided a dozen columns from both select statements):

CREATE PROCEDURE [AbnormalReadingSource_Get]
(
    @WhereClause varchar (2000)  ,
    @OrderBy varchar (2000)  ,
    @PageIndex int   ,
    @PageSize int   
)
AS
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
BEGIN
    DECLARE @PageLowerBound int
    DECLARE @PageUpperBound int

    -- Set the page bounds
    SET @PageLowerBound = @PageSize * @PageIndex
    SET @PageUpperBound = @PageLowerBound + @PageSize

    IF (@OrderBy is null or LEN(@OrderBy) < 1)
    BEGIN
        -- default order by to first column
        SET @OrderBy = '[Result]'
    END

    -- SQL Server 2005 Paging
    declare @SQL as nvarchar(4000)
    SET @SQL = 'WITH PageIndex AS ('
    SET @SQL = @SQL + ' SELECT'
    IF @PageSize > 0
    BEGIN
        SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
    END
    SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
    SET @SQL = @SQL + ', [Result]'
    SET @SQL = @SQL + ' FROM [AbnormalReadingSource]'
    IF LEN(@WhereClause) > 0
    BEGIN
        SET @SQL = @SQL + ' WHERE ' + @WhereClause
    END
    SET @SQL = @SQL + ' ) SELECT'
    SET @SQL = @SQL + ' [Result],'
    SET @SQL = @SQL + ' FROM PageIndex'
    SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
    IF @PageSize > 0
    BEGIN
        SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
    END
    exec sp_executesql @SQL

    -- get row count
    SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
    SET @SQL = @SQL + ' FROM [AbnormalReadingSource]'
    IF LEN(@WhereClause) > 0
    BEGIN
        SET @SQL = @SQL + ' WHERE ' + @WhereClause
    END
    exec sp_executesql @SQL

END

The database transaction isolation level is READ COMMITTED so setting the isolation level in the stored procedure isn’t necessary but is in the .NetTiers templates used to generate the stored procedure. Can I use the readpast hint to avoid the locking that occurred? Do I need to provide any other hints when using readpast?

  • 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-30T03:53:00+00:00Added an answer on May 30, 2026 at 3:53 am

    You could try READPAST but remember it will not allow “dirty” reads so your result set could be missing some records if something is momentarily locked.

    Similarly you could try your select statement with: WITH(NOLOCK)

    NOLOCK will read the “dirty” data but then you run the risk of it being rolled back.

    Both will avoid blocking, both have their pros and cons.

    This article should help clarify:
    http://www.techrepublic.com/article/using-nolock-and-readpast-table-hints-in-sql-server/6185492

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

Sidebar

Related Questions

I have a view defined in SQL server 2008 that joins 4 tables together.
I have a view in SQL Server that is somewhat similar to the following
I have a View that can vary significantly, depending on the 'mode' a particular
I have a view that is joining two tables and ordering by the first
I have one specific view created in my DB(joins about 5-6 tables with a
In a SQL Server database, I have two tables, s and t. A further
I have the requirement to search several different tables in my SQL Server database.
In SQL Server I have put a clustered index on a view to eliminate
I have a c# application (2008) that gets data from sql server (2005). I
I use SQL Server 2008 Express with Advanced Services. I have a view: IF

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.