How to implement auto increment column value alphabetical?

Manish Singh

I have a table tbl_login and I want my column id to be auto increment and alphabetical also. Please help me. Thanks in advance.

ID      Name    Pass
101A    Mohan   1234
102B    Madan   4321
103C    Ram     12334
KumarHarsh

Very Nice question.

i) This id can be generated upto how much digit ?like 10,000 or 1,00,000 or more

ii) You should throw little more example randomly start from 101 .specially throw few example from 4 digit and few from 5 digits.

iii)how you are going to implement it.Like will you insert single row or you will insert bulk rows. Implemented SCRIPT can be optimize and change according to requirement once requirement is clear.

iv) Test my script.First thoroughly test it from any number between 101 to 921

Just change the value of @input

DECLARE @Input INT = 127--change here
DECLARE @Output VARCHAR(10) = ''
    ,@TempOutput VARCHAR(10) = ''
DECLARE @Base INT = 100
    ,@z INT = 26
    ,@Rem INT
DECLARE @Tempinput INT = @Input

WHILE (
        @Tempinput > 0
        AND @input > @Base + @z
        )
BEGIN
    SET @TempOutput = ''

    IF (@Tempinput > @Base)
    BEGIN
        SET @Rem = @Tempinput % @Base
    END

    IF (
            (@Rem % @z) = 0
            AND (@Rem / @z) > 1
            )
    BEGIN
        SET @Tempinput = (@Rem / @z) - 1
        SET @Rem = @Rem % @z

        PRINT '23'
    END
    ELSE
    BEGIN
        IF (@Rem > @z)
        BEGIN
            SET @Tempinput = @Rem / @z
            SET @Rem = @Rem % @z

            PRINT @Tempinput
        END
        ELSE
        BEGIN
            SET @Rem = @Tempinput % @z
            SET @Tempinput = @Tempinput / @z
        END
    END

    IF (
            @Rem > 0
            AND @Rem <= @z
            )
        SET @TempOutput = CHAR(@Rem + 64)
    ELSE IF (@Rem = 0)
        SET @TempOutput = 'Z'
    SET @Output = @TempOutput + @Output
END

IF (@input <= @Base + @z)
    SET @Output = CHAR((@input % @Base) + 64)

SELECT cast(@Input AS VARCHAR(10)) + @Output

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to set auto increment column value with condition

how to get the maximum value of a varchar column and auto increment it

How to implement auto increment in spark SQL(PySpark)

Change mysql auto increment id column value

How to find if a column is auto_increment in MySQL

How to create a column with auto increment and condition pandas

How to generate a Auto Increment column for a XML query?

How to auto increment database column in Java derby?

How to add an auto increment column in java?

How to reset auto increment column in SQL Server

How to auto increment counter by repeteaded values in a column

MSSQL - fetch Auto increment column value and save it in a another column

How to to get the value of an auto increment column in postgres from a .sql script file?

How to auto increment a column so the value increases by 1 when a new item is added using Laravel?

How to auto_increment a value from a column when inserting a new row

how to auto-increment a value in php?

How Use Auto Increment value in two columns

how to insert auto increment value for trigger in postgresql?

How to set initial value and auto increment in MySQL?

How to add auto increment value to realm

how to define start value for GORM auto increment

How to implement an auto_increment composite primary key with MySQL InnoDB?

Auto Increment by Column and by Group

Auto increment column by condition

Start generating auto increment column value from default in slick

MySQL insert varchar value into int auto increment column

Insert same auto increment value to another column of same table

Auto increment column value by 3 columns in copying across a row

Column with auto_increment default value is NULL when querying