DECLARE @years INT = 120 -- 随机日期值自1899年起的年数间隔范围 SELECT CAST(CHECKSUM(newID())%(365*@years) AS DATETIME)+RAND()
扩展:
DECLARE @years INT = 120 -- 随机日期值自1899年起的年数间隔范围 SELECT TOP 100 ROW_NUMBER()OVER(ORDER BY a.ID) AS ID, CAST(CHECKSUM(newID())%(365*@years) AS DATETIME)+RAND() AS RandomDate FROM syscolumns a,syscolumns b
参考资料:http://bbs.csdn.net/topics/340165720