I have database with job numbers, scheduled date, and scheduled hours such as this:
J410 | 11/14/2016 | 50|
I have been asked to produce a report with one line for each day of the job like this:
J410 | 11/14/2016 | 10 |
J410 | 11/15/2016 | 10 |
J410 | 11/16/2016 | 10 |
J410 | 11/17/2016 | 10 |
J410 | 11/18/2016 | 10 |
The logic is that we assume 10
hour days, so the total number of hours divided by 10 = the number of days
, then the users want a line for each day.
I can easily get the number of days like this:
SELECT CEILING(Hours / 10.0)
- Note that some hours don't divide evenly by 10
so I am rounding up.
I don't have the slightest idea how to attack the problem of creating (for reporting only) additional lines for each date.
My initial thoughts are to select the records into a temp table and then select each record and use a WHILE
statement to duplicate the records until the number of days have been reached.
Can anyone provide a better idea ?