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

  • Home
  • SEARCH
  • 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 8404039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:29:40+00:00 2026-06-09T22:29:40+00:00

How do I write a SQL statement that would arrange a column of serial

  • 0

How do I write a SQL statement that would arrange a column of serial numbers so that they are in groups with a range of 1000 or less (based on their serial numbers)? The numbers are not currently sorted but would end up like the example below. There are only two numbers in the first example group (having a difference of 31). The third number has a difference of 6443 from the second number placing it in a separate grouping (>1000). The next 4 numbers are grouped based on their range of …4015 to …4865 (diff of 850).

I’m still a noob with < 6 months of TSQL. I don’t even know where to start with this one.

serial_num
----------  
33XG547909  
33XG547940  

33XG554383  

33XG564015 
33XG564282 
33XG564289  
33XG564308  
33XG564314  
33XG564353  
33XG564865  

33XG569023       

34LT242788  
34LT242812  
  • 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-09T22:29:42+00:00Added an answer on June 9, 2026 at 10:29 pm

    If you’re looking to group items in a sliding scale where each item can be grouped with the thousand nearest items, you’ll have a lot of trouble since there would be so many combinations. They probably wouldn’t be helpful either unless you’re looking at a specific item and trying to find the thousand closest for just that one item.

    I think Astander has a good solution, but it doesn’t cover the starting portion of the serial. It looks like your solution is a simple as:

    SELECT  SerialNumber,
            LEFT(SerialNumber, LEN(SerialNumber) - 3) GroupNumber
    FROM    YourTable
    ORDER BY 2, 1
    

    With the results being

    SerialNumber GroupNumber
    ------------ -----------
    33XG547909   33XG547
    33XG547940   33XG547
    33XG554383   33XG554
    33XG564015   33XG564
    33XG564282   33XG564
    33XG564289   33XG564
    33XG564308   33XG564
    33XG564314   33XG564
    33XG564353   33XG564
    33XG564865   33XG564
    33XG569023   33XG569
    34LT242788   34LT242
    34LT242812   34LT242
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to write a T-SQL statement, that structures data to be loaded
I am trying to find out how to write an SQL statement that will
I'm trying to write an insert statement for a SQL Server table that inserts
I am trying to write a sql statement that I have 2 tables Store
I'm trying to write an SQL statement that duplicates all rows WHERE employee =
How can I write an sql statement that returns a list of how many
I'm trying to write a fairly complex JPQL statement that sorts results based on
I am trying to write a sql statement that will allow me to check
I need to write SQL statement that will return an html table and specify
I'm trying to write a SQL statement that will allow me to select a

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.