Tsql 汇总表行ssrs 2008
这是我的情况。我需要创建一个报告,显示每个打开的工单,还显示上一个人工日期(如果有),以及自上一个人工日期以来经过的天数。以下是创建数据集的SQL的表示形式:Tsql 汇总表行ssrs 2008,tsql,ssrs-2008,Tsql,Ssrs 2008,这是我的情况。我需要创建一个报告,显示每个打开的工单,还显示上一个人工日期(如果有),以及自上一个人工日期以来经过的天数。以下是创建数据集的SQL的表示形式: select segments.date_created, headers.order_number segments.segment_id lines.line_type lines.line_qty * lines.unit_price line_amt, case
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
样本输出为:
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
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
需要注意的两件事是,我将日期1900-01-01插入所有非人工线的时钟日期,即:非3号线。在我的报告中,我按订单号和段id进行分组
报告输出需要:
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
报告输出为:
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
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
由于数据集的每一行都是订单行,因此订单总额总和正确,但是报告将数据集的所有行总和为总DALL值,这是不正确的。我只想对报告中显示的DALL值求和。在DALL字段的表达式中,如果时钟日期='1900-01-01',我将插入一个0。我需要所有的行,因为服务经理需要所有的工作订单,无论是否有劳动力,他希望这些订单表示为0 DALL。我已经和他谈过这将如何扭曲他的结果,显然他喜欢扭曲的结果。我想我已经提供了足够的信息,如果您还需要了解其他信息,请告诉我。我前一阵子就知道了,只是太忙了,没法把它放在这里。我想,因为在SSRS中没有真正的方法来实现这一点,所以我选择了SQL。我没有将1900-01-01放在labor_date字段中,而是允许SQL将空值放在其中。现在,当它将所有内容相加时,将忽略空值