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
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.
Comments