22.4.11

Generating Alpha numeric values in SQL Server like Identity property

My application has three atributes id, name, sal and a create button. but the task is the user should not enter id according to his choice..
it should be generated automatically..... when new user is registering...
the no's should be like that a1,a2,a2.... b1,b2,..... no's should be alphanumeric...
s there any solution for this... help me out....

Answer for the above query,

DECLARE @ALPHA_VAL CHAR(1) , @INT_VAL VARCHAR(1000)

DECLARE @VAL INT =97, @VAL1 INT =1
WHILE @VAL <= 122
BEGIN


      SET @VAL1=1

      WHILE @VAL1 < 1000

       BEGIN

                SET @ALPHA_VAL = CHAR(@VAL)
                SET @INT_VAL = CONVERT(CHAR,@VAL1)
                SET @INT_VAL= @ALPHA_VAL + @INT_VAL

                PRINT @INT_VAL
                SET @VAL1 = @VAL1+1

        END
SET @VAL=@VAL+1
END

The output is

a1
a2
a3
a4
....b1,b2,....b1000...c1,c2.......etc... to z1000

Cheers,

Venkatesan Prabu .J
Head - WWW.Kaashivinfotech.com
http://venkattechnicalblog.blogspot.com/

No comments:

Post a Comment