[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

How to write SQL Syntax that generate random number of 13 digits?

Posted on 2011-10-13
9
Medium Priority
?
294 Views
Last Modified: 2012-05-12
Hello,

How to write SQL Syntax that generate random number of 13 digits?

Thanks

0
Comment
Question by:zaki100
8 Comments
 
LVL 71

Assisted Solution

by:Éric Moreau
Éric Moreau earned 1000 total points
ID: 36962403
you can use the SP found at http://www.brettb.com/SQL_Help_Random_Strings.asp and set the @ValidCharacters only digits only
0
 
LVL 32

Accepted Solution

by:
awking00 earned 1000 total points
ID: 36962412
declare @Random int;
declare @Upper int;
declare @Lower int;

set @Lower = 1000000000000
set @Upper = 9999999999999
select @Random = ROUND(((@Upper - @Lower - 1) * RAND() + @Lower), 0)
select @Random
0
 
LVL 8

Expert Comment

by:Salah Eddine ELMRABET
ID: 36962415
Hi Zaki,

Could you please explain your needs in details? where will you use this random numbers? the idea is to make it on the script (PHP, ASP, VB...) and then insert the result on the database using normal sql syntax.

Other wise if you are using stored procedures in the SQL server side.

so could you please explain so you can gave a better answer?

BR
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 71

Expert Comment

by:Éric Moreau
ID: 36962447
selmrabet, your code can work but only if you replace int with BIGINT

declare @Random bigint;
declare @Upper bigint;
declare @Lower bigint;
0
 
LVL 71

Expert Comment

by:Éric Moreau
ID: 36962455
I meant awking00
0
 
LVL 32

Expert Comment

by:awking00
ID: 36962565
selmrabet,
Thanks for pointing that out. I usually don't have a need to generate random numbers so large :-)
0
 
LVL 32

Expert Comment

by:awking00
ID: 36962576
And I meant emoreau! Sorry for any confusion.
0
 
LVL 72

Expert Comment

by:Qlemo
ID: 37218527
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question