Here is my situation. I need to create a report that shows each open work order and that also shows the last labor date, if there is one, and the number of elapsed days since the last labor date. Here is a representation of the SQL that created the dataset:
select segments.date_created,
headers.order_number
segments.segment_id
lines.line_type
lines.line_qty * lines.unit_price line_amt,
case when lines.line_type = 3
then max(clocking.clock_date)
else convert(date, '1900-01-01')
end last_clock_date,
case when lines.line_type = 3
then datediff(day, max(clocking.clock_date), getdate())
else datediff(day, convert(date, '1900-01-01'), getdate())
end DALL
from segments inner join headers on segments.header_id = headers.header_id
left join lines on header.header_id = lines.header_id
left join clocking on header.header_id = clocking.header_id and
segments.segment_id = clocking.segment_id and
lines.line_id = clocking.line_id
where headers.status = 0
and segments.branch = @branch
and headers.folder_id in ('400', '401')
and headers.order_number not like 'WP%'
group by headers.order_number, segments.segment_id,
lines.line_type, segments.date_created, lines.line_qty,
lines.unit_price
Sample output is:
date_created order_number segment_id line_type line_amt clock_date DALL
2012-05-10 HA025050 1 1 288.58 1900-01-01 41072
2012-05-10 HA025050 1 3 81.00 2012-05-10 35
2012-05-10 HA025050 2 1 22.90 1900-01-01 41072
2012-04-26 W7184315 1 3 1062.50 2012-05-08 37
2012-04-26 W7184315 1 1 69.68 1900-01-01 41072
2012-04-26 W7184315 1 1 61.96 1900-01-01 41072
2012-04-27 W7184357 1 1 682.11 1900-01-01 41072
Two things to note, I am jamming the date 1900-01-01 into clock_date for all lines that are not labor lines ie: not line 3. In my report I am grouping by order_number and segment_id.
Report output needs to be:
order_number segment_id amount date_created clock_date DALL
HA025050 1 369.58 2012-05-10 2012-05-10 35
HA025050 2 22.90 2012-05-10 0
W7184315 1 1194.14 2012-04-26 2012-05-08 37
W7184357 1 682.11 2012-04-27 0
Count: 4 Total: 2268.73 Days: 72 Avg: 18
Report output is:
order_number segment_id amount date_created clock_date DALL
HA025050 1 369.58 2012-05-10 2012-05-10 35
HA025050 2 22.90 2012-05-10 0
W7184315 1 1194.14 2012-04-26 2012-05-08 37
W7184357 1 682.11 2012-04-27 0
Count: 4 Total: 2268.73 Days: 205432 Avg: 51358
Since each line of the dataset is an order line the order total amount sums correctly, however the report is summing all of the lines of the dataset for the total DALL value, which is incorrect. I want to sum just the DALL values that appear in the report. In the expression for the DALL field I am inserting a “0” if the clock_date = ‘1900-01-01’. I need all of the lines because the service manager wants all work orders whether there is labor on it or not, and he wants those orders represented as 0 DALL. I have already had the conversation with him about how that will skew his results, apparently he likes skewed results. I think I have given enough information, if you need to know anything else let me know.
I figured it out a while back, just been too busy to place it here. I thought since there was not really a way to do it in SSRS, I went to the SQL. Instead of placing
1900-01-01in thelabor_datefield I allowed SQL to place a null. Now when it adds everything up the nulls get ignored.