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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:06:30+00:00 2026-06-11T22:06:30+00:00

I will be creating a sequential Serial Number made from Hexadecimal values With this

  • 0

I will be creating a sequential Serial Number made from Hexadecimal values

With this Format:

XX-XX-XX-YYYY
Which XX-XX-XX is default value
And YYYY is the incrementing hexa decimal value

Now to create the serial number based on hex value I need Add 6 to the last generated hex value

MIN: 2D41 + 6 = 2D47    
     2D47 + 6 ... and so on
MAX: 4100   generation of serial will stop when I meet the MAX value.

I already created it in c# but I need to do it on SQL

int num1 = int.Parse("2D41", NumberStyles.HexNumber); //Convert hex to int
int result = num1 + 6; //Add + 6 for increment
string myHex = result.ToString("X");  //Convert result to hex
MessageBox.Show(myHex);  // result 2D47

How can this be done in T-SQL?

  • 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-11T22:06:31+00:00Added an answer on June 11, 2026 at 10:06 pm

    Hope this helps you

    declare @seed varchar(max) = '2D41';
    declare @limit varchar(max) = '4100';
    
    select convert(int, convert(varbinary(max), '0x'+@seed,1)),
           convert(int, convert(varbinary(max), '0x'+@limit,1));
    
    ;with seedlimit(seed, limit) as (
        select convert(int, convert(varbinary(max), '0x'+@seed,1)),
               convert(int, convert(varbinary(max), '0x'+@limit,1))
    )
    select SerialNumber = 'XX-XX-XX-' + right(convert(varchar(10),cast(s.seed + 6 * v.number as varbinary(max)),1),4)
    from seedlimit s
    join master.dbo.spt_values v on type='p'
    where s.seed + 6 * v.number <= s.limit;
    

    The basic ingredients are in there for you to create a view/procedure/function out of the answer,

    Output:

    SerialNumber
    -------------
    XX-XX-XX-2D41
    XX-XX-XX-2D47
    ...
    XX-XX-XX-40F7
    XX-XX-XX-40FD
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following program I'm creating will allow the user will input values to create
I've struggled with this a good bit this morning; I'm creating what will eventually
I'm creating a bash script that will run a process in the background, which
I will be creating numerous sites. Each site will have default users. These users
Portal Technology Assessment in which we will be creating a placement portal for the
I am creating a service for which I will use MongoDB as a storage
I will be creating an Application that will be showing the Products in a
I will be creating flatfiles and based on the data in the batch, it
I have one model User and will be creating another one Category . Both
Im creating a Yii app where i will save images into the database. Now

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.