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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:11:56+00:00 2026-06-16T00:11:56+00:00

I have some sql that will not return the rows I need unless I

  • 0

I have some sql that will not return the rows I need unless I specify that as a criteria in the where clause. If I uncomment the part below that is commented out, it will give me the rows I want. If I leave it commented out, those rows are not returned in my result set.

Does this make sense? Can anyone see anything I’m doing wrong? Thanks.

SELECT     
   RTRIM(c.comp2) + '-' + l.Loc_Name, 
   MAX(RTRIM(g.mega_location_num) + '-' + g.mega_location_name) 
FROM       
   mkt_share_comp c, gldm_location g, mkt_share_locs l 
WHERE     
   RTRIM(c.comp1) = g.location_num
   AND c.comp2 = l.Loc_No
   AND LEN(c.comp2) = 5 AND c.is_deleted = 0 AND l.is_deleted = 0
   --and  g.mega_location_num = '450'
GROUP BY
   RTRIM(c.comp2) + '-' + l.Loc_Name
ORDER BY
   MAX(RTRIM(g.mega_location_num) + '-' + g.mega_location_name) 
  • 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-16T00:11:57+00:00Added an answer on June 16, 2026 at 12:11 am

    This comparison:

    MAX(RTRIM(g.mega_location_num) + '-' + g.mega_location_name)
    

    Will be doing a MAX based on the string value that you’re constructing. So if there are any g.mega_location_num values which start with a digit greater than 4 (or start with 4 and have a second digit greater than 5, etc), then that value will be the MAX value returned.

    To start to fix this, I would first switch to the ANSI join style that Kuya has suggested. I would then consider including an appropriate ROW_NUMBER() expression to locate the “genuine” maximum value from the g table and to be able to retrieve multiple columns from that maximal row (to allow the string construction to proceed)

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

Sidebar

Related Questions

I have some script that is delivering a series of rows from an SQL
I have some sql statements that calculates some numbers. It's possible (with bonus points/penalty
I have some Crystal Reports connecting to a Sql Server db that I would
I have some code that uses the SQL Server 2005 SMO objects to backup
I have C# application that must store some information into MS SQL that would
Hi I have some software written in VB6.0 that uses an SQL Server, but
I'm having some trouble with an SQL statement that have to find the number
I am doing some performance testing and have found that SQL seems to be
I have a Microsoft SQL server DB that imports some data which needs a
I have a form that is trying to insert some data into an SQL

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.