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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:07:44+00:00 2026-05-24T16:07:44+00:00

I have a query which works for every order except one. Here’s the part

  • 0

I have a query which works for every order except one. Here’s the part that’s not working right now:

DECLARE @ordernum INT
SELECT @ordernum = 101257

SELECT  o.CustomerID , ups.*
            From dbo.orders o with (NOLOCK)
      left join (
           Select top 1 UPSAccountInfo.UPSAccount as UPSAccount1
      ,UPSAccountInfo.CID as UPSCID
      ,UPSAccountInfo.Address as  UPSAddress1
      ,UPSAccountInfo.DesiredService  UPSDesiredService1
      ,UPSAccountInfo.Address2 as UPSAddress2
      ,UPSAccountInfo.Suit as UPSSuite
      ,UPSAccountInfo.city as UPSCity
      ,UPSAccountInfo.Country as UPSCountry
      ,UPSAccountInfo.SP as UPSState
      ,UPSAccountInfo.Zip as UPSZip
  FROM UPSAccountInfo
  with (NOLOCK)
   order by date desc
      ) ups on ups.upscid = o.customerid
 WHERE o.OrderNumber = @ordernum

This is part of a larger query, I just pulled out what isn’t working. By not working, I mean that it returns the customerid, but none of the UPSAccountInfo. So it is, in fact, bringing back a record.

However, this works just fine:

Select top 1 UPSAccountInfo.UPSAccount as UPSAccount1
      ,UPSAccountInfo.CID as UPSCID
      ,UPSAccountInfo.Address as  UPSAddress1
      ,UPSAccountInfo.DesiredService  UPSDesiredService1
      ,UPSAccountInfo.Address2 as UPSAddress2
      ,UPSAccountInfo.Suit as UPSSuite
      ,UPSAccountInfo.city as UPSCity
      ,UPSAccountInfo.Country as UPSCountry
      ,UPSAccountInfo.SP as UPSState
      ,UPSAccountInfo.Zip as UPSZip
  FROM UPSAccountInfo
  WHERE CID = 58939
   order by date desc

Both the queries have a customerid of 58939, so what’s going on?

Any help is appreciated. This has been working great for several months but now, for this one order, it doesn’t. It’s driving me nuts.

Oh, and feel free to dump on this code all you want. I didn’t write it, I inherited it.

Thanks!

  • 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-24T16:07:45+00:00Added an answer on May 24, 2026 at 4:07 pm

    What if you just use a regular join instead of a subquery join? Like this:

    SELECT TOP 1
        o.CustomerID 
        ,ups.UPSAccount as UPSAccount1
       ,ups.CID as UPSCID
       ,ups.Address as  UPSAddress1
       ,ups.DesiredService  UPSDesiredService1
       ,ups.Address2 as UPSAddress2
       ,ups.Suit as UPSSuite
       ,ups.city as UPSCity
       ,ups.Country as UPSCountry
       ,ups.SP as UPSState
       ,ups.Zip as UPSZip
    FROM dbo.orders o 
    LEFT OUTER JOIN UPSAccountInfo ups
    ON ups.cid = o.customerid
    WHERE o.OrderNumber = @ordernum
    ORDER BY ups.date DESC
    

    If you don’t need more than one row from dbo.orders, that should work.

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

Sidebar

Related Questions

I have this query which works correctly in MySQL. More background on it here
I have a query which works fine in MySQL, but when I run it
I have the following query which works fine with MySQL but refuses to work
I have the following which works in SQL Query Analyzer . select oh.* from
G'day! I have one million different words which I'd like to query for in
I have a query which part of a SP which is executed fairly regularly,
I have a relatively complex query, with several self joins, which works on a
I have this query that works fine. It selects rows into the SY.UserOptions table
Here is the issue I am having: I have a large query that needs
I have a query using a FREETEXTTABLE full text search which works perfectly for

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.