SQL-Server随机日期值

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

posted @ 2014-12-29 11:34  被谋杀的诗篇  阅读(405)  评论(0编辑  收藏  举报