Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Random number !

$
0
0
I have a function which generate random number in range :[code="sql"]CREATE FUNCTION Func_Rand ( @MAX BIGINT , @UNIQID UNIQUEIDENTIFIER )RETURNS BIGINTAS BEGIN RETURN (ABS(CHECKSUM(@UNIQID)) % @MAX)+1 ENDGO[/code] If you run this script you always get result between 1 and 4[code="sql"]SELECT dbo.Func_Rand(4, NEWID()) [/code]BUT, in this script sometimes have no result !!!!!!! why??[code="sql"]SELECT 'aa'WHERE dbo.Func_Rand(4, NEWID()) IN ( 1, 2, 3, 4 )[/code]

Viewing all articles
Browse latest Browse all 3145

Trending Articles