stored procedures - I want to generate random date in SQL Server -
can please tell me want generate 100 random dates table:
create table dates (dt date)
this code ok want put below code in loop generate 100 random dates
select dateadd(second, (rand() * 60 + 1), dateadd(minute, (rand() * 60 + 1), dateadd(day, (rand() * 365 + 1), dateadd(year, -1, getdate())
or other simple code generate random
date give me if can.
thanks
praviin
here example:
select top 100 dateadd(ss, cast(abs(checksum(newid())) int), '19000101') rnddate master..spt_values
fiddle http://sqlfiddle.com/#!3/9eecb7/6049
for predefined range:
with cte as(select row_number() over(order number) % 366 r master..spt_values) select top 100 dateadd(dd, r, '20141231') cte order newid()
r
contain values 1 366. adding '20141231'
give values desired range.
Comments
Post a Comment