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 2000 Forums
 SQL Server Development (2000)
 random generate a 12 digit number

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-05-16 : 10:20:16
Bart Higdon writes "how can i randomly generate a 12 digit number within a stored procedure, then have the proc return the generated number"

M.E.
Aged Yak Warrior

539 Posts

Posted - 2002-05-16 : 10:47:07
you'll need to create a stored proc with an output variable. look it up in BOL.

Use the rand() function to create the 12 digit number. To make it 12 digit use

select convert(numeric(12,0),rand() * 1000000000000)

I think thats enough 0's. if it comes back as 11 digits or less.. it just means there are leading 0's.



Go to Top of Page

nschoot
Starting Member

2 Posts

Posted - 2002-05-17 : 07:13:17
or user 99999999999 + RandomNumber to never have leading zero's :-)

Go to Top of Page
   

- Advertisement -