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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:41:21+00:00 2026-06-09T13:41:21+00:00

Currently I have a query which is partly based on a join on two

  • 0

Currently I have a query which is partly based on a join on two tables according to two number columns within them.

Say one table has a number like 123456789999 (NUM1)

And the other table has a number ranging from 1 – 9999 (NUM2)

I want to pull out the records which have ‘NUM2’ within the 5th – 8th digits of ‘NUM1’

Currently I am doing something like this,

FROM Table1 AS T INNER JOIN Table2 AS S 
ON SUBSTRING(T.num1, 5, 4) = S.num2

I know it should be retrieving approx 100 records, but I only get 8. I believe it to be because of the small ranges within number two. Where have I gone wrong? OR how could my code be made more robust/effective?

  • 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-09T13:41:23+00:00Added an answer on June 9, 2026 at 1:41 pm

    You need to use CAST like this:

    FROM Table1 AS T INNER JOIN Table2 AS S 
    ON CAST(SUBSTRING(T.num1, 5, 4) AS INT) = S.num2
    

    SEE THIS FIDDLE

    For more info see SQL SERVER – Convert Text to Numbers (Integer) – CAST and CONVERT

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

Sidebar

Related Questions

I currently have a database with two tables in it one hold lets say
I currently have quite a messy query, which joins data from multiple tables involving
I currently have a MultiCriteria query, which filters the results based on the ids
I currently have a SQL query that returns a number of fields. I need
I currently have an SQL query which is currently called multiple times like this
Currently I have an sql query which finds the amount of records in the
I currently have a query running on my site which looks for all rows
I currently have this query: select customers.emailaddress, MAX(orders.orderdate) as last order from orders join
I have an access query which creates some output, 3 columns named e.g. A
I have a mysql query which outputs 6 columns of related data, I'm specifically

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.