Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 unique alpha numeric numbers

Author  Topic 

buzzi
Starting Member

48 Posts

Posted - 2008-07-02 : 14:34:17
Hi all,
I was looking at the below post to see how to generate unique alpha numeric numbers

http://www.sqlteam.com/article/custom-auto-generated-sequences-with-
sql-server

I was specifically looking at the below function

create function CustomerNumber(@i int)
returns char(5)
as
begin
return (char(@i / 26000 % 26 + 65) +
char(@i / 1000 % 26 + 65) +
char(@i / 100 % 10 + 48) +
char(@i / 10 % 10 + 48) +
char(@i % 10 + 48))
end

I was able to figure out adding "65" the 1st 2 statements as these are base 26, the last 3 are base 10, but not able to figure out why "48" is added to the last 3??

Thanks for any help

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-02 : 14:49:57
It is used to get last three digit numbers

See what it returns

Select char(48)

So it is basically adding 0 to a number. Since char function is used, you need to use that

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-07-02 : 14:50:14
If you have questions about an article, you should post it in the article comments so that the author can answer.

CODO ERGO SUM
Go to Top of Page
   

- Advertisement -