SSRS 2016查询错误?我想念什么?

时间:2019-04-04 19:00:39

标签: reporting-services

当我在查询设计器中运行查询时,它返回正确的信息。当我运行与报表完全相同的代码时,它将忽略我的where子句,而我的数据库只会将所有内容都插入表/图表中。如何只报告查询内容?

此查询通过MS查询工作,并且在SSRS查询设计器中工作。但它不会在报告生成器中返回正确的信息

SELECT q.entityid,
       i.reqnum as "Request Number",
       CASE 
         WHEN (p.work_group) IS NULL THEN (w.work_group)
         ELSE (p.work_group)
       END as "Workgroup",
       w.creator_userid    as  "Creator",
       a.store_number as "Store Number", 
       s.division  as   "Division",
       s.region  as  "Region",
       s.city  as   "City",
       s.state   as   "State",
       CASE
         WHEN CAST(a.relo_date AS INT) = 10101 THEN MONTH(a.open_date)
         ELSE MONTH(a.relo_date)
       END as "Date Occupied", 
       i.servicetyp as "Service Type", 
       i.subservtyp as "Sub Service Type",
       CASE
         WHEN (v.vdrname) IS NULL THEN (w.vendor_name)
         ELSE (v.vdrname) 
       END as "Vendor",
       i.vendinvnum as "Invoice Num",
       i.invdate as "Invoice Date",
       i.invamount as "Invoice Amount", 
       i.description as "Description", 
       i.class as "Class", 
       i.createuser as "Created By", 
       i.createdate as "Create Date",
       a.bldtype  as  "Building Type",
       a.prttype as  "Property Type" 

FROM dwdata.fminvoice i 
       LEFT JOIN dwdata.fmaccrnt a
              ON  i.storenum = a.store_number     
       LEFT JOIN dwdata.fmpohdr p 
              ON i.reqnum = p.purordnum 
       LEFT JOIN dwdata.fmvendor v 
              ON p.ordrvennum = v.vdrnum
       LEFT JOIN dwmirror.store s 
              ON s.sstrno=i.storenum
       LEFT JOIN dwdata.fmwrkord w 
              ON i.reqnum = w.wrkordnum
       LEFT JOIN dwdata.fmsrvreq q
              ON (w.service_request_number = q.service_request_number OR p.service_request_number = q.service_request_number)

WHERE a.lease_use = 'STORE' and i.invdate >= '2019-01-01'
       AND
      (i.invdate >= case
                      when cast(a.relo_date AS INT) =10101 THEN a.open_date
                      ELSE a.relo_date
                    END
       AND
       i.invdate <= case
                      when cast(a.relo_date AS INT) =10101 THEN a.open_date
                      ELSE a.relo_date
                    END + 365 days )
      AND a.entityid= q.entityid

我希望WHERE子句在发送结果之前在服务器上实际过滤结果,但事实并非如此。我正在得到一切。

****代码已发布。除了报表生成器之外,where子句还可以在其他任何地方使用。

1 个答案:

答案 0 :(得分:0)

Steve-o169已启动。代替

 i.invdate <= case
                      when cast(a.relo_date AS INT) =10101 THEN a.open_date
                      ELSE a.relo_date
                    END + 365 days )

尝试

 i.invdate <= case
                      when cast(a.relo_date AS INT) = 10101 
                      THEN DateAdd('D',365, a.open_date)
                      ELSE DateAdd('D',365,a.relo_date)
                    END)

https://docs.microsoft.com/en-us/sql/t-sql/functions/dateadd-transact-sql?view=sql-server-2017