Login     Register

        Contact Us     Search

XLeratorDB/math Documentation

SQL Server RAND function


RAND
 
Updated: 17 August 2010
Use RAND to calculate a random number greater than or equal to zero and less than one. 
Syntax
SELECT [westclintech].[wct].[RAND] ()
Arguments
None
 
Return Types
float
Remarks
·         Unlike the built-in SQL Server RAND function, RAND is evaluated for every row in the resultant table.
Example
 
with mycte as
(
      select 1 as seq
      union all
      select seq + 1
      from mycte
      where seq < 15
)
      select seq
      ,rand() as [SQL Server RAND]
      ,wct.rand() as [XLDB RAND]
      from mycte

Here is the result set
seq         SQL Server RAND        XLDB RAND
----------- ---------------------- ----------------------
1           0.717683577913778      0.320075967691334
2           0.717683577913778      0.242518944291069
3           0.717683577913778      0.939540304240701
4           0.717683577913778      0.995485696135315
5           0.717683577913778      0.390991905650971
6           0.717683577913778      0.847310724479799
7           0.717683577913778      0.0338573758405467
8           0.717683577913778      0.162934983399244
9           0.717683577913778      0.407146586492377
10          0.717683577913778      0.186449045740706
11          0.717683577913778      0.252528679920915
12          0.717683577913778      0.942039038585549
13          0.717683577913778      0.857604925612895
14          0.717683577913778      0.957765087979192
15          0.717683577913778      0.442119654211433
 
(15 row(s) affected)
See Also


Copyright 2008-2024 Westclintech LLC         Privacy Policy        Terms of Service