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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:43:39+00:00 2026-06-11T18:43:39+00:00

I have a complex SQL statement that I need to match up two table

  • 0

I have a complex SQL statement that I need to match up two table based on a join. The the intial part of the complex query has a location number that is stored in a table as a Smallint and the second table has the Store number stored as a CHAR(4). I have been able to cast the smallint to a char(4) like this:

CAST(STR_NBR AS CHAR(4)) AND LOCN_NBR

The issue is that because the Smallint suppresses the leading ‘0’ the join returns null values from the right hand side of the LEFT OUTER JOIN.

Example

Table set A(Smallint)             Table Set B (Char(4))
|   96     |                      |  096     |
|   97     |                      |  097     |
|   99     |                      |  099     |
|  100     |  <- These return  -> |  100     |
|  101     |  <- These return  -> |  101     |
|  102     |  <- These return  -> |  102     |

I need to add make it so that they all return, but since it is in a join statement how do you append a zero to the beginning and in certain conditions and not in others?

  • 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-11T18:43:40+00:00Added an answer on June 11, 2026 at 6:43 pm

    I was able to successfully match it out to obtain a 3 digit location number at all times by doing the following:

    STR_NBR was originally defined as a SmallINT(2)
    LOCN_NO was originally defined as a Char(4)

    SELECT ...
    FROM TABLE_A AS A
    JOIN TABLE_B AS B
      ON CAST(SUBSTR(DIGITS(A.STR_NBR),3,3)AS CHAR(4)) = B.LOCN_NO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a complex SQL Query, that needs to be filtered further. Part of
I have a somewhat complex SQL query that is pulling from a table of
I have a complex sorting problem with my SQL statement. I have a table
I have a complex sql query that I have in a stored procedure and
I have following somewhat complex sql query which has horrible performance, 'certainly' due to
I have a complex Powershell script that gets run as part of a SQL
I have a very complex Linq to SQL query that returns a result set
I have a fairly complex SQL query that pulls different types of products from
I need a regex that will determine if a given SQL statement has a
I have quite a complex piece of code (JQuery and HTML5 Web SQL) that

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.