我有这个代码转换为CR。将@ReportType转换为公式和参数到CR时,我遇到的问题最多。有什么建议吗?在工作中我感到难过,没有任何支持。
select i.IncidentTypeDescription,
isnull(sum(datediff(second, i.IncidentStartedDateTime, i.IncidentDate)), 0) as avgrectoinit,
isnull(sum(datediff(second, i.IncidentDate, i.FirstUnitDispatchedTime)), 0) as avginittodisp,
isnull(abs(sum(datediff(second, i.FirstUnitDispatchedTime, i.FirstUnitArrivedTime))), 0) as avgdisptoarrive,
isnull(sum(datediff(second, i.FirstUnitArrivedTime, i.RouteClosedTime)), 0) as avgarrivetoclose,
count(*) as reccount
FROM MV_Incident i
WHERE i.IncidentNumber LIKE N'bvpd%'
AND i.ReportNumber LIKE N'bvpd%'
and i.IncidentStartedDateTime >= @StartDate
and i.IncidentStartedDateTime < dateadd(day, 1, @EndDate)
and (
(@ReportType = 'All') and (i.CallSource = i.CallSource or i.CallSource is null) or
(@ReportType = 'Officer' and (i.CallSource in ('Officer', 'Mobile', 'Field Initiated', 'Mobile Initiated'))) or
(@ReportType = 'NonOfficer' and (i.CallSource not in ('Officer', 'Mobile', 'Field Initiated', 'Mobile Initiated') or i.CallSource is NULL))
)
group by i.IncidentTypeDescription
order by i.IncidentTypeDescription
答案 0 :(得分:0)
您可以在创建数据库连接时使用命令选项在水晶报表中使用查询。
第二个选项是,使用以下查询并创建参数并在记录选择公式中写入条件,该公式将向晶体报告中添加where子句。
select i.IncidentTypeDescription, i.IncidentNumber ,i.ReportNumber ,i.CallSource ,
isnull(sum(datediff(second, i.IncidentStartedDateTime, i.IncidentDate)), 0) as avgrectoinit,
isnull(sum(datediff(second, i.IncidentDate, i.FirstUnitDispatchedTime)), 0) as avginittodisp,
isnull(abs(sum(datediff(second, i.FirstUnitDispatchedTime, i.FirstUnitArrivedTime))), 0) as avgdisptoarrive,
isnull(sum(datediff(second, i.FirstUnitArrivedTime, i.RouteClosedTime)), 0) as avgarrivetoclose,
count(*) as reccount
FROM MV_Incident i
group by i.IncidentTypeDescription,i.IncidentNumber ,i.ReportNumber ,i.CallSource
order by i.IncidentTypeDescription,i.IncidentNumber ,i.ReportNumber ,i.CallSource
现在进行水晶报表设计并创建两个参数Start date
和End Date
,并将记录选择公式中的where条件写为:
i.IncidentNumber LIKE N'bvpd%'
AND i.ReportNumber LIKE N'bvpd%'
and i.IncidentStartedDateTime >= @StartDate
and i.IncidentStartedDateTime < dateadd(day, 1, @EndDate)
and (
(@ReportType = 'All') and (i.CallSource = i.CallSource or i.CallSource is null) or
(@ReportType = 'Officer' and (i.CallSource in ('Officer', 'Mobile', 'Field Initiated', 'Mobile Initiated'))) or
(@ReportType = 'NonOfficer' and (i.CallSource not in ('Officer', 'Mobile', 'Field Initiated', 'Mobile Initiated') or i.CallSource is NULL))
)
不要忘记创建报告类型公式。
让我知道任何问题