Random number dataset
Posted by Diego em Março 28, 2013
Just a proc I had to create to produce a dataset with a date and a random number.
The fun par is that it also generates a random number of rows.
The reason I had to do it is to do a time analysis between sets. Imagine that each execution represents a day and you want to know the difference between today and yesterday.
CREATE PROCEDURE generateRandomthings
DECLARE @test TABLE (
DECLARE @i int = (SELECT CAST((RAND()*10)+1 AS int))
DECLARE @date DATETIME = GETDATE()
WHILE @i>0 BEGIN
INSERT INTO @test (report_date, [_number])
SELECT @date, (SELECT CAST((RAND()*10)+1 AS int))
SET @i-= 1
SELECT * FROM @test