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)
 easy random nr

Author  Topic 

mike13
Posting Yak Master

219 Posts

Posted - 2007-10-02 : 08:00:22
Hi,

What would be the easiest way create a 7 digit random nr?

tnx,

Mike

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-02 : 08:13:31
1) SELECT 1000000 + ABS(CHECKSUM(NEWID())) % 9000000
2) SELECT ABS(CHECKSUM(NEWID())) % 10000000



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Zoroaster
Aged Yak Warrior

702 Posts

Posted - 2007-10-02 : 08:23:41
Or http://www.brettb.com/SQL_Help_Random_Numbers.asp

The 1st one works Peso (and is very slick!) but the second one is not always 7 digits.



Future guru in the making.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-02 : 10:21:14
Yes it is. It has leading zeros. But you can't see them.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Zoroaster
Aged Yak Warrior

702 Posts

Posted - 2007-10-02 : 10:41:16
quote:
Originally posted by Peso

Yes it is. It has leading zeros. But you can't see them.



E 12°55'05.25"
N 56°04'39.16"




Profound.



Future guru in the making.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-10-02 : 10:42:44
ROTFLOL!



_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

mike13
Posting Yak Master

219 Posts

Posted - 2007-10-02 : 17:26:26
thanks a lot
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2007-10-02 : 19:50:43
8469639

This number is completely random. I typed it with my eyes closed.


Damian
"A foolish consistency is the hobgoblin of little minds." - Emerson
Go to Top of Page

Zoroaster
Aged Yak Warrior

702 Posts

Posted - 2007-10-02 : 20:02:50
quote:
Originally posted by Merkin

8469639

This number is completely random. I typed it with my eyes closed.


Damian
"A foolish consistency is the hobgoblin of little minds." - Emerson



Genius!



Future guru in the making.
Go to Top of Page
   

- Advertisement -