sql server 2008 - get each date for two different time for 3 years -


i trying create table in want data shown

which has 3 columes shift_date, shift# , shift_starttime. each day there going shift 1 , shift 2 , shift 1 shift_starttime 6:30 , shift 2 16:20 upto 2020.

try use recursive cte:

with cte1 (     select cast('2017-04-01' datetime) [shift_date],          cast(1 smallint) [shift#],         cast('2017-04-01 06:30:00.000' datetime) [shift_starttime]     union     select dateadd(day, 1, [shift_date]), [shift#], dateadd(day, 1, [shift_starttime])     cte1     dateadd(day, 1, [shift_date]) <= '2020-12-31' ), cte2 (     select cast('2017-04-01' datetime) [shift_date],          cast(2 smallint) [shift#],         cast('2017-04-01 16:30:00.000' datetime) [shift_starttime]     union     select dateadd(day, 1, [shift_date]), [shift#], dateadd(day, 1, [shift_starttime])     cte2     dateadd(day, 1, [shift_date]) <= '2020-12-31' ) select *  dbo.test_shift_date_table --use table name cte1 union select *  cte2 option(maxrecursion 32000) 

Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -