【发布时间】:2015-06-03 13:31:56
【问题描述】:
我目前设置了一个基于 4 个参数返回结果的报告。这些参数是@StartDate、@EndDate、@EmployeeID 和@SampleType,它们都很容易解释。它还按样品类型分组,然后按日期分组。
报告看起来像这样(或多或少):
Sample Type Employee Name Date Time Spent on Sample
A Name1 4/6 7
Name1 4/6 8
Name2 4/6 15
B Name1 4/6 12
Name2 4/6 11
Name2 4/6 13
(姓名为计算字段,按employeeID分组) 如果要返回多行,报表将返回正确的结果,但如果只有一行要返回,则不显示任何内容。它不会仅使用特定的employeeID 或特定的SampleType 执行此操作,仅当只有一条记录要呈现时。因此,使用上面的虚拟报告,如果 @StartDate 是 4/6,@EndDate 是 4/6,@EmployeeID 是 Name1,@SampleType 是 B,预览将不会显示一个结果。但是如果@EmployeeID 是Name2,它会是两行。
当只有一行应该返回时,是否有任何明显的原因导致参数无法正常工作?
下面是查询的副本:
SELECT MasterSampleDescription, CollectedDateTime, LabArrivalDateTime, CreatedDateTime, TimeDiffCollectLab, TimeDiffLabCreate, TimeDiffCollectCreate,
TimeDiffCollectStart, TimeDiffCollectEnd, TimeDiffSampleStartEnd, SampleStart, SampleEnd, FirstName, LastName, AVG(TimeDiffCollectEnd) AS AvgTimeDiffCollect,
TimeDiffLabArrivalSampleEnd, TimeDiffCreationStart, UserID
FROM vwTimeAnalysis
WHERE (CollectedDateTime >= @StartDate) AND (CollectedDateTime < DATEADD(Day, 1, @EndDate))
GROUP BY MasterSampleDescription, CollectedDateTime, LabArrivalDateTime, CreatedDateTime, TimeDiffCollectLab, TimeDiffLabCreate, TimeDiffCollectCreate,
TimeDiffCollectStart, TimeDiffCollectEnd, TimeDiffSampleStartEnd, SampleStart, SampleEnd, FirstName, LastName, TimeDiffLabArrivalSampleEnd,
TimeDiffCreationStart, UserID
HAVING (UserID = @EmployeeName) AND (MasterSampleDescription = @SampleType)
ORDER BY CollectedDateTime, LastName, MasterSampleDescription
【问题讨论】:
-
HAVING 子句用于聚合函数条件。
-
我的错,QueryDesigner 将这些过滤器默认为 HAVING 而不是 WHERE。更正了查询,仍然没有看到想要的结果。它从查询中正确提取行,但无法在报告中显示它们。
-
这听起来更像是一个 SSRS 问题,而不是一个查询问题。你能给我们更多关于(可能是矩阵)控制设置的信息吗?那里有什么特别的事情吗?你的组定义是什么?
-
如果“预览”是指 Visual Studio 中的“预览”选项卡,那么我会忽略这一点。它通常不可靠/具有误导性。部署您的报告并在用户运行时对其进行测试。
-
@MikeHoney 谢谢。它显然可以在 Dev 中使用,而不是在 Visual Studio 的“预览”选项卡中。无缘无故让我发狂。非常感谢。
标签: sql reporting-services parameters parent-child