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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:36:03+00:00 2026-05-26T22:36:03+00:00

ID numbers in my database have a code embedded in the last 3 characters.

  • 0

ID numbers in my database have a code embedded in the last 3 characters. When comparing these ids for equality sometimes it is allowable to ignore the last 3 characters.

I.e. 12345001 == 12345009 should be true.

I usually do this with the following where clause:

where floor(id1/1000) == floor(id2/1000)

but in the case where I know id1 is stored in ‘base’ form where the last 3 digits are zero the following would also work:

where id1 == floor(id2/1000)*1000

It would also be possible with use of substring.


Q: Can anybody tell me from experience which of these three methods is the most efficient, or recommend the best (most accurate) way to profile these three different queries.

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-26T22:36:04+00:00Added an answer on May 26, 2026 at 10:36 pm

    Running either id value through a function will prevent any index use & the simple mathematic operations on integers would be faster than a cast to a character type followed by a substring comparison.

    If you wanted to optimise this fully you could add a computed column to derive floor(id/1000), then index that and use it in your WHERE clause.

    (Another one for you to benchmark abs(id1-id2)<1000 but basic series of mathematical transforms like this would only have temporal significance over huge datasets)

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

Sidebar

Related Questions

in my database i have phone numbers with country code , which look somthing
I have a database filled with some codes like EE789323 990 78000 These numbers
These numbers are stored in the Database. They origionate from Delphi code. Although I
I have a database with millions of phone numbers with free-for-all formatting. Ie, the
I have an application for entering in serial numbers to a database. A serial
I have a huge database which holds pairs of numbers (A,B), each ranging from
I have a number of scripts used to build a database. These need to
I have a database full of autopart numbers that needs old part numbers prices
I have a site where users enter a numeric code of 10 numbers: xxxxxxxxxx
I have code, which returns me a row out of a database, con =

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.