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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:16:47+00:00 2026-05-30T01:16:47+00:00

I am trying to update a #temp table from a linked server using a

  • 0

I am trying to update a #temp table from a linked server using a top clause but am getting a very odd result – it seems to be ignoring the order by in my code.

I can fix the specific problem programatically but would like to know if this is a one off issue or there is a general problem with the way i have linked the servers.

The query is being run on a 2005 SQL Server (9.0.3042) linked to a 2008 SQL Server R2 (10.50.279) linked via the Microsoft OLE DB Provider for SQL Server.

The query looks like this – i have already created #TempTable which has the columns Id, Date and PrevDate and inserted data into the Id and Date columns.

update #TempTable 
set PrevDate =      
(select top 1 
    d.Date
from   
    linkedserver.DB.dbo.Date as d
where
    d.Id = #TempTable.Id
    and d.Date < #TempTable.Date
order by
    d.Date desc)

The select is not picking the top 1, it appears to be picking the first date entered into the table for the specific Id and ignoring the order by clause.

  • When I just do a select, it works fine
  • When I put in the PrevDate via the inital insert, it works fine.
  • When I use a Max rather than a Top, it works fine.
  • When I run the exact same query/scenario on the 2008 SQL Server via a link (same provider) back to the 2005 SQL Server, it works fine

I am not looking for a fix for this specific query but would like to know if this is an isolated incedent or some fundamental problem with 2005 to 2008 linking that is going to manifest itself in very hard to find ways.

Thanks,
Tim

  • 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-30T01:16:48+00:00Added an answer on May 30, 2026 at 1:16 am

    I have some bad news. I have replicated this issue here. It looks to me to be an issue with SQL Server 2005’s query plan (I tested with a later version too, v 9.0.4035):

    Image: Query plan for update statement

    (sorry I can’t embed images here, not enough reputation)

    The details for that remote query:

    Image: Remote Query details

    There is no ORDER BY statement sent to the remote server, so the results that come back are indeed just the TOP (1) in an arbitrary order, which is likely to be in the order of the primary key. It seems to me that SQL Server should have emitted an ORDER BY Date desc there.

    Therefore, I have to conclude that other queries like this, in this environment, could easily have the same issue (so, not an isolated incident).

    By the way, there is a Microsoft Connect issue already raised for this one, from 2009: connect.microsoft.com/SQLServer/feedback/details/446017/missing-order-by-in-remote-query-with-update-statement

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

Sidebar

Related Questions

I am trying to query from a temp table and i keep getting this
I'm trying to update a hashtable in a loop but getting an error: System.InvalidOperationException:
I am trying to update a field in a table with data from another
Hi I am having a problem when trying to update a table using an
In SQL/Transact SQL, I am trying to update a temp table to take the
Using Informix, I've created a tempory table which I am trying to populate from
I trying to update a model on a callback but the validation is causing
I am trying to update a column in my table which was last inserted.
So I'm trying to update an object in my MS SQL 2005 database using
I'm trying to update an NText field in SQL 2000 using Classic ASP. Here

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.