mercredi 24 juillet 2019

pick random and unique items SQL

We are trying to populate a table with Random (and unqiue) values between 1-37. The following query is not picking unique however.

truncate table [dbo].[webscrape]
declare @date date = '1990-01-01',
@endDate date = Getdate()

while @date<=@enddate
begin
insert into [dbo].[webscrape](date,value1,value2,value3,value4,value5)
SELECT @date date,convert(int,(RAND()*37-1+1)) value1,
convert(int,(RAND()*37-1+1)) value2,
convert(int,(RAND()*37-1+1)) value3,
convert(int,(RAND()*37-1+1)) value4,
convert(int,(RAND()*37-1+1)) value5

set @date = DATEADD(day,1,@date)
end




Aucun commentaire:

Enregistrer un commentaire