Kingston Dhasian (6/20/2013)
Great job posting the sample data and the structure of the table:-)
Can you also provide the expected results based on your sample data
That will help us to test the solution ourselves before we post
The What I Tried section comes close to how i want it to output. But notice the date 2013-06-03 is spanning 3 days. This isn't shown in that. Instead i need the output to look like the result from this table
create Table #tempOutput(datestart date, AM int, PM int)
insert Into #TempOutput (dateStart,AM,PM)
Select '2013-06-03',4,5 Union ALL --first day between 2013-06-03, 2013-06-05 hours split between AM and PM
Select '2013-06-04',4,5 Union ALL --Second day between 2013-06-03, 2013-06-05 hours split between AM and PM
Select '2013-06-05',4,5 Union ALL --Third day between 2013-06-03, 2013-06-05 hours split between AM and PM
Select '2013-06-07',0,1 Union ALL -- Time between 2013-06-07 14:00:00.000, 2013-06-07 15:00:00.000 hours split between AM and PM
Select '2013-06-08',1,0 Union ALL -- Time between 2013-06-08 08:00:00.000, 2013-06-08 09:00:00.000 hours split between AM and PM
Select '2013-06-27',4,5 Union ALL --first day between 2013-06-27, 2013-06-28 hours split between AM and PM
Select '2013-06-28',4,5 Union ALL --Second day between 2013-06-27, 2013-06-28 hours split between AM and PM