首页 > 代码库 > SQL-Server随机日期值

SQL-Server随机日期值

DECLARE @years INT = 120 -- 随机日期值自1899年起的年数间隔范围SELECT CAST(CHECKSUM(newID())%(365*@years) AS DATETIME)+RAND()

扩展:

DECLARE @years INT = 120 -- 随机日期值自1899年起的年数间隔范围SELECT TOP 100ROW_NUMBER()OVER(ORDER BY a.ID) AS ID,CAST(CHECKSUM(newID())%(365*@years) AS DATETIME)+RAND() AS RandomDateFROM syscolumns a,syscolumns b

参考资料:http://bbs.csdn.net/topics/340165720

SQL-Server随机日期值