Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
sql_server 217
t-sql 211
tsql 116
sqlserver 96
BRH 78
#SQLServer 66
#TSQL 56
SQL Server 34
function 11
SSMS 9

Archive · View All
August 2007 17
August 2010 8
June 2012 7
June 2011 7
November 2007 7
August 2012 6
May 2012 6
November 2011 6
August 2011 6
October 2011 6

Madhivanan's TSQL Blog

Generating Random Numbers - Part II

Oct 10 2007 8:20AM by Madhivanan   

There are many methods to generate random numbers. Here are some of them

select number from
(
select top 10000 abs(checksum(newid())) as number 
from sysobjects s1 cross join sysobjects s2
) as T

select number from
(
select top 1000 abs(cast(cast(newid() as varbinary(10)) as int)) as number 
from sysobjects s1 cross join sysobjects s2
)  as T

If you want to generate 4 digits random number, then use

 select number/power(10,len(number)-4) as number from
(
select top 10000 abs(checksum(newid())) as number 
from sysobjects s1 cross join sysobjects s2
) as T

If you want to generate 2 digits random number, then use

select number/power(10,len(number)-2) as number from
(
select top 10000 abs(checksum(newid())) as number 
from sysobjects s1 cross join sysobjects s2
) as T

If you use SQL Server 2005, you can also apply the same approach on the following query

 select row_number() over (order by s1.name) as number 
from sysobjects s1 cross join sysobjects s2

Tags: t-sql, sql_server, random_numbers,


Madhivanan
3 · 40% · 12947
1
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

"Generating Random Numbers - Part II" rated 5 out of 5 by 1 readers
Generating Random Numbers - Part II , 5.0 out of 5 based on 1 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]