Generate random SQL Server 2008 time test data

后端 未结 2 1518
予麋鹿
予麋鹿 2021-01-18 07:25

I am trying to generate a large data set which includes time datatype in SQL Server 2008. I already have some non-time data in a table so I\'d like to keep the entire proce

2条回答
  •  情话喂你
    2021-01-18 08:00

    To generate 100 rows of test data you can use the below.

    WITH E00(N) AS (SELECT 1 UNION ALL SELECT 1),
            E02(N) AS (SELECT 1 FROM E00 a, E00 b),
            E04(N) AS (SELECT 1 FROM E02 a, E02 b),
            E08(N) AS (SELECT 1 FROM E04 a, E04 b),
            E16(N) AS (SELECT 1 FROM E08 a, E08 b),
            E32(N) AS (SELECT 1 FROM E16 a, E16 b)
    SELECT TOP 100 CAST(DATEADD(SECOND,ABS(CHECKSUM(NEWID()))%3600,'08:00') AS TIME)
    FROM E32
    

提交回复
热议问题