为Reporting Services滚动12个月

时间:2016-07-18 14:33:29

标签: sql postgresql reporting-services

我正在尝试为SSRS报告提供12个月的滚动数据。我不确定它是否应该在我的查询中,在下面,或在SSRS的表达式中。日期和时间的字段称为CALL_TIME,仅在我的WHERE子句中有特色。其格式为'2016-04-01 13:46:00'。

这是我的问题:

select

Street
Town
Incidents
IncidentType A
IncidentType B
IncidentType C

FROM OPENQUERY
(POSTGRESQL, 

Street
Town
Incidents
IncidentType A
IncidentType B
IncidentType C

FROM
(

select

COUNT(I.INC_NUM) as Incidents,

COUNT(case when i.INC_TYPE = ''A'' THEN 1
      end)
"IncidentType A"
COUNT(case when i.INC_TYPE = ''B'' THEN 1
      end)
"IncidentType B"
COUNT(case when i.INC_TYPE = ''C'' THEN 1
      end)
"IncidentType C"

FROM Table i

WHERE I.CALL_TIME  >= ''2016-01-01''

GROUP BY i.INC_NUM

) i

RESULT

Street      Incidents      IncidentType A   IncidentType B   IncidentType C
back lane       5                2                 0                 3

2 个答案:

答案 0 :(得分:1)

我认为你只需要替换你的where子句:

     WHERE I.CALL_TIME  >= (now()-('12 months'::interval))

答案 1 :(得分:0)

将您的where子句更改为:

WHERE I.CALL.TIME between DATEADD(Year, -1, getdate()) AND getdate()
相关问题