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

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -