N
N
Nikolai2020-11-19 16:48:52
SQL Server
Nikolai, 2020-11-19 16:48:52

How to fill a table with two columns with arbitrary data?

Good afternoon.
Prompt how to fill the table with the test data in MS SQL. In one table, numbers from 1 to 15 must be repeated 20 to 30 times. In another arbitrary date in the range of 2008 to 2016. Can this be done or is it fiction?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Tsvetkov, 2021-01-18
@Skofield2016

SELECT a.ID, 
DATEADD( s, RAND( CONVERT( INT, CAST( NEWID() AS BINARY(16) ), 1)) * 252460800, '20080101' ) AS dt
FROM 
(VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15)) AS A (ID)
CROSS JOIN
(VALUES  (1),  (2),  (3),  (4),  (5),  (6),  (7),  (8),  (9), (10), 
        (11), (12), (13), (14), (15), (16), (17), (18), (19), (20),
        (21), (22), (23), (24), (25), (26), (27), (28), (29), (30)) AS B(C)
ORDER BY NEWID()

V
Vladimir Korotenko, 2020-11-19
@firedragon

Rand sql server handbook

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question