我正在尝试在报告中创建一个表格,如下所示:
数据集基于此查询:
SELECT
DATENAME(dw, CurrentReadTime) AS 'DAY',
DATEPART(dw, CurrentReadTime) AS 'DOW',
CAST(datename(HH, CurrentReadTime) as int) AS 'HOD',
AVG([Difference]) AS 'AVG'
FROM
Consumption
INNER JOIN Readings ON Readings.[RadioID-Hex] = Consumption.[RadioID-Hex]
WHERE
CONCAT([Building], ' ', [Apt]) = @ServiceLocation
GROUP BY
CurrentReadTime
ORDER BY
DATEPART(DW, CurrentReadTime),
CAST(DATENAME(HH, CurrentReadTime) AS INT)
此表中的数据返回如下:
在报表生成器中,我已将此代码添加到报表属性中:
Function GetRangeValueByHour(ByVal Hour As Integer) As String
Select Case Hour
Case 6 To 12
GetRangeValueByHour = "Morning"
Case 12 to 17
GetRangeValueByHour = "Afternoon"
Case 17 to 22
GetRangeValueByHour = "Evening"
Case Else
GetRangeValueByHour = "Overnight"
End Select
Return GetRangeValueByHour
End Function
此代码到"行组":
=Code.GetRangeValueByHour(Fields!HOD.Value)
当我执行报告时,选择目标服务位置的参数,我得到这个结果:
正如您将注意到的那样,"时间和#34;正在显示报告属性代码中符合CASE表达式的第一个结果;但是,我确认了所有" HOD" (存储为整数)通过对此结果执行SUM来组合在一起。
此外,实际表值(.05,.08等)仅返回首先满足VB代码中CASE语句要求的HOD结果。
这些是我需要解决的问题,但无法弄清楚:
对于仍在阅读的人,感谢您的帮助!如果您需要其他信息,请与我们联系。
答案 0 :(得分:0)