E
E
embiid2021-08-10 12:30:46
SQL Server
embiid, 2021-08-10 12:30:46

How to create a script to populate a table of time intervals?

Table TimeSlot; id, start time, end timeHow to make a script that will make 23/24 entries starttime - endtime0.00-1.00, 1.00-2.00, etc.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2021-08-10
@embiid

The corresponding columns are of type TIME.

DECLARE @I INT = 0
WHILE @I < 24 BEGIN
  INSERT [TimeSlot] ([Start Time], [End Time]) 
    VALUES ( CAST( DATEADD( hh, @I, 0 ) AS TIME ),  CAST( DATEADD( hh, @I + 1, 0 ) AS TIME ))
  SET @I = @I + 1
END

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question