How Do I Create Random Data Script Samples?

How Can We Help?

< Back

Answer

To generate random data:

Sample One

SELECT 'IT', ABS(CONVERT(BIGINT,CONVERT(BINARY(8), NEWID()))) % 50 AS Random
UNION ALL
SELECT 'HCP', ABS(CONVERT(BIGINT,CONVERT(BINARY(8), NEWID()))) % 50 AS Random
UNION ALL
SELECT 'Stationary', ABS(CONVERT(BIGINT,CONVERT(BINARY(8), NEWID()))) % 24 AS Random

Replacing the IT, HCP and Stationary as required, the random seed of 50, 50 and 24 should also be amended as required.

Resulting data of the above.

ffaafd66ad899581b47538dde203ef1e

Sample Two

SELECT [Date] = DATEADD(Day,-Number,GetDate()),
ABS(CONVERT(BIGINT,CONVERT(BINARY(8), NEWID()))) % 10000 AS Random
FROM  master..spt_values
WHERE Type='P'
AND DATEADD(day,-Number,GetDate()) >= DATEADD(DAY, -30, GETDATE())

Replacing the 10000 as the seed value required.

Resulting data of the above.

0a94d84d06459685f1cf94dadb2f3606

Comments are closed.

This is the legacy version of the XMPro Documentation site. For the latest XMPro documentation, please visit documentation.xmpro.com

X