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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:53:30+00:00 2026-06-06T11:53:30+00:00

Client wants to append a field with a literal increment based on a count.

  • 0

Client wants to append a field with a literal increment based on a count.

The range goes from ‘aa‘ to ‘zz‘.

‘aa‘ represents a count of 1 and ‘zz‘ represents the max value in the range: 676

I have sql that almost works but would appreciate an expert eye to get me over the last hurdle.

--Constants
DECLARE @START_ASCII INT = 97
DECLARE @ASCII_OFFSET INT = 1
DECLARE @ALPHABET_LETTER_COUNT INT = 26

--Variables
DECLARE @RecordCount INT = 0
DECLARE @FirstLetter VARCHAR(1) = NULL
DECLARE @SecondLetter VARCHAR(1) = NULL

SET @RecordCount = 1 --Range is 1 to 676 (e.g. 'aa' to 'zz')

SET @FirstLetter = CHAR(round(@RecordCount / @ALPHABET_LETTER_COUNT, 2, 1) + @START_ASCII) 
SET @SecondLetter = CHAR((((@RecordCount - @ASCII_OFFSET) % @ALPHABET_LETTER_COUNT) + @START_ASCII)) 

SELECT @FirstLetter + @SecondLetter

The problem with the above sql involves the first letter. It works till the end of the alphabet is reached for the second letter. For example, at a count of 26, I expect ‘az‘, but instead get ‘bz‘.

I want to keep the SQL small and tight (e.g. no CASE statements). Is there a small tweak I can make to the above code so that it will work?

Or, if there is just a smarter way to skin this cat, I’d like to know that.

  • 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-06T11:53:31+00:00Added an answer on June 6, 2026 at 11:53 am

    I would think of this as computing the base-26 representation of @RecordCount-1 (range 0 to 675). Then map the two-digits of the base-26 number to the ASCII characters:

    SET @FirstLetter = CHAR(floor((@RecordCount-1) / @ALPHABET_LETTER_COUNT) + @START_ASCII)
    SET @SecondLetter = CHAR(((@RecordCount-1) % @ALPHABET_LETTER_COUNT) + @START_ASCII)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A client wants to ensure that I cannot read sensitive data from their site,
Client wants a button on the mobile web app that launches a QR code
Client wants to edit DotNetNuke skin and he is not a programmer, so I'm
My client wants their app to always show a WARNING screen when the application
A client wants a multilingual site with a CMS. Is there a Ruby on
A client wants to add functionality to a system that will distribute large files(~700mb)
A client wants to use Google Apps for employees but they want to offer
My client wants me to make a plugin that intercepts the banner on a
Our client wants to support both SQL Server and Oracle in the next project.
I want to consume Java based web service with c#.net client. The problem is,

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.