antiskeptic
Programmer
I am using SQL Server 2000. I am creating a stored procedure of which the output will be used in a Crystal report. But I need help getting the output right. I am making a payroll audit report to see how many consecutive days are taken off during a pay period. I have tried several different avenues but nothing really works.
The closest I seem to get is this temp table that stored all the worked and off days, and the dates. The output from this table is like this:
(PTO = Paid Time Off / WT = Work Time)
Name TimeCode ItemDate
George Jetson PTO 2004-08-09
George Jetson WT 2004-08-10
George Jetson WT 2004-08-11
George Jetson WT 2004-08-12
George Jetson WT 2004-08-13
George Jetson PTO 2004-08-18
George Jetson PTO 2004-08-19
George Jetson PTO 2004-08-20
Fred Flintstone WT 2004-08-11
Fred Flintstone PTO 2004-08-12
Fred Flintstone PTO 2004-08-13
Fred Flintstone PTO 2004-08-16
Fred Flintstone WT 2004-08-17
Fred Flintstone WT 2004-08-18
Fred Flintstone WT 2004-08-19
Fred Flintstone WT 2004-08-20
Johnny Quest WT 2004-08-11
Johnny Quest PTO 2004-08-12
Johnny Quest PTO 2004-08-13
Johnny Quest WT 2004-08-16
Johnny Quest PTO 2004-08-17
Johnny Quest PTO 2004-08-18
Johnny Quest WT 2004-08-19
Johnny Quest WT 2004-08-20
Now George has the 18, 19, & 20th as paid off so I would want to see him on the report for those days.
Fred would also appear on the report even though the dates are not exactly consecutive. The skip in dates from the 13th to the 16th is over a weekend, so for the purposes of this data output, this is considered consecutive.
And Johnny would not show up at all because he only takes off 2 days at a time.
So I need to figure out how to count (like a running total) the codes when they switch from WorkTime or PaidTimeOff. And be able to take into consideration skipped over days. The only way the PTO "breaks" is if a WT timecode interrupts the "flow". (If that makes any sense) ANd I don't care about any of the PTO if it's not 3 days or more in a row.
Can anyone see of a way I can do this?
My final out put needs to be this layout below:
Name TimeCode Min Date Max Date
George Jetson PTO 2004-08-18 2004-08-20
Fred Flintstone PTO 2004-08-12 2004-08-16
Thanks in advance for any tips, pointers, or shoves in the right direction. THank you!
SIncerely,
Antiskeptic
The closest I seem to get is this temp table that stored all the worked and off days, and the dates. The output from this table is like this:
(PTO = Paid Time Off / WT = Work Time)
Name TimeCode ItemDate
George Jetson PTO 2004-08-09
George Jetson WT 2004-08-10
George Jetson WT 2004-08-11
George Jetson WT 2004-08-12
George Jetson WT 2004-08-13
George Jetson PTO 2004-08-18
George Jetson PTO 2004-08-19
George Jetson PTO 2004-08-20
Fred Flintstone WT 2004-08-11
Fred Flintstone PTO 2004-08-12
Fred Flintstone PTO 2004-08-13
Fred Flintstone PTO 2004-08-16
Fred Flintstone WT 2004-08-17
Fred Flintstone WT 2004-08-18
Fred Flintstone WT 2004-08-19
Fred Flintstone WT 2004-08-20
Johnny Quest WT 2004-08-11
Johnny Quest PTO 2004-08-12
Johnny Quest PTO 2004-08-13
Johnny Quest WT 2004-08-16
Johnny Quest PTO 2004-08-17
Johnny Quest PTO 2004-08-18
Johnny Quest WT 2004-08-19
Johnny Quest WT 2004-08-20
Now George has the 18, 19, & 20th as paid off so I would want to see him on the report for those days.
Fred would also appear on the report even though the dates are not exactly consecutive. The skip in dates from the 13th to the 16th is over a weekend, so for the purposes of this data output, this is considered consecutive.
And Johnny would not show up at all because he only takes off 2 days at a time.
So I need to figure out how to count (like a running total) the codes when they switch from WorkTime or PaidTimeOff. And be able to take into consideration skipped over days. The only way the PTO "breaks" is if a WT timecode interrupts the "flow". (If that makes any sense) ANd I don't care about any of the PTO if it's not 3 days or more in a row.
Can anyone see of a way I can do this?
My final out put needs to be this layout below:
Name TimeCode Min Date Max Date
George Jetson PTO 2004-08-18 2004-08-20
Fred Flintstone PTO 2004-08-12 2004-08-16
Thanks in advance for any tips, pointers, or shoves in the right direction. THank you!
SIncerely,
Antiskeptic