T-SQL和SSRS结果之间的差异

时间:2019-06-15 06:33:54

标签: tsql group-by ssrs-tablix

我在T-SQL中创建了以下代码(请参见下文) 它在SSMS环境中运行良好,但是当我将其发布到SSRS(报表服务)中时, [总计] [已完成] 字段的数字在SSRS中是非常不同的比SSMS中的要高-远远高于SSMS中的

这是我的代码:

     USE [WH]
     GO

       DECLARE @MonthBOP date = '05-01-2019'
       DECLARE @MonthEOP date = '05-01-2019'
       DECLARE @EHRRegionsWHID int = -1
       DECLARE @EHRProgramsWHID int = -1
       DECLARE @EHRProgramTypesWHID int = -1


    SELECT        
          ehrrgn.WHID AS [EHRRegionWHID] 
        , ehrrgn.EHRRegion 
        , ehrprgtype.WHID AS [EHRProgramTypeWHID] 
        , ehrprg.WHID AS [EHRProgramWHID]
        , ehrprg.EHRProgramCode
        , ehrprg.EHRProgramName 
        , poswh.WHID AS [PositionWHWHID]
        , poswh.PositionNameWH
        , posfamwh.WHID AS [PositionFamilyWHWHID]
        , posfamwh.PositionFamilyNameWH
        , pos.WHID AS [PositionWHID]
        , empl.EmployeeCode
        , empl.EmployeeName
        , ct.ServiceDate
        , dd.YearMonthSort
        , ct.StaffFK
        , COUNT(ct.ServiceFK) AS [Completed]
        , tt.Total

   FROM          
       Fact.EHRClinicalTransaction ct
       INNER JOIN Dimension.EHRProgram ehrprg ON 
                       ct.ProgramFK = ehrprg.WHID

       INNER JOIN Dimension.EHRRegion ehrrgn ON 
                       ehrprg.EHRRegionFK = ehrrgn.WHID

       INNER JOIN Dimension.EHRProgramType ehrprgtype ON 
                       ehrprg.EHRProgramTypeFK = ehrprgtype.WHID

       INNER JOIN Dimension.EHRStaff ehrstf ON ct.StaffFK = ehrstf.WHID 

       INNER JOIN Dimension.PaycomEmployee empl ON 
                       ehrstf.PaycomEmployeeFK = empl.WHID

       INNER JOIN Dimension.PaycomPosition pos ON 
                       empl.PaycomPositionFK = pos.WHID

       INNER JOIN Dimension.PaycomPositionWH poswh ON 
                       pos.PositionWHFK = poswh.WHID

       INNER JOIN Dimension.PaycomPositionFamilyWH posfamwh ON 
                       pos.PositionFamilyWHFK = posfamwh.WHID

       INNER JOIN Dimension.[Date] dd ON ct.ServiceDate = dd.[Date]

       INNER JOIN 
                ( 
                 SELECT 
                       ct.[StaffFK] 
                      ,COUNT(ct.[ServiceFK]) AS [Total]

                 FROM 
                     Fact.EHRClinicalTransaction ct
                     INNER JOIN Dimension.EHRProgram ehrprg ON 
                                      ct.ProgramFK = ehrprg.WHID 
                     INNER JOIN Dimension.EHRRegion ehrrgn ON 
                                    ehrprg.EHRRegionFK = ehrrgn.WHID
                     INNER JOIN Dimension.EHRProgramType ehrprgtype ON 
                             ehrprg.EHRProgramTypeFK = ehrprgtype.WHID
                     INNER JOIN Dimension.EHRStaff ehrstf ON 
                            ct.StaffFK = ehrstf.WHID 
                     INNER JOIN Dimension.PaycomEmployee empl ON 
                            ehrstf.PaycomEmployeeFK = empl.WHID
                     INNER JOIN Dimension.PaycomPosition pos ON 
                            empl.PaycomPositionFK = pos.WHID
                     INNER JOIN Dimension.PaycomPositionWH poswh ON 
                            pos.PositionWHFK = poswh.WHID
                 INNER JOIN Dimension.PaycomPositionFamilyWH posfamwh ON 
                            pos.PositionFamilyWHFK = posfamwh.WHID
                 INNER JOIN Dimension.[Date] dd ON 
                            ct.ServiceDate = dd.[Date]

              WHERE
                    (ct.[ServiceDate] BETWEEN @MonthBOP AND @MonthEOP) 
               AND ((ehrrgn.WHID IN (@EHRRegionsWHID)) OR 
                    (-1 IN (@EHRRegionsWHID))) AND (ehrrgn.WHID <>-1)
               AND ((ehrprg.WHID IN (@EHRProgramsWHID)) OR 
                    (-1 IN (@EHRProgramsWHID))) AND (ehrprg.WHID <>-1)
               AND ((ehrprgtype.WHID IN (@EHRProgramTypesWHID)) OR 
               (-1 IN (@EHRProgramTypesWHID))) AND (ehrprgtype.WHID <>-1)

           GROUP BY
                  ct.[StaffFK] 

             ) tt ON  ct.StaffFK = tt.StaffFK

  WHERE        
       (ct.IsNoShow = 0) 
  AND (ct.IsDeleted = 0)
  AND (ct.[ServiceDate] BETWEEN @MonthBOP AND @MonthEOP) 
  AND ((ehrrgn.WHID IN (@EHRRegionsWHID)) OR (-1 IN (@EHRRegionsWHID))) 
  AND (ehrrgn.WHID <>-1)
  AND ((ehrprg.WHID IN (@EHRProgramsWHID)) OR (-1 IN (@EHRProgramsWHID))) 
  AND (ehrprg.WHID <>-1)
  AND ((ehrprgtype.WHID IN (@EHRProgramTypesWHID)) OR 
       (-1 IN (@EHRProgramTypesWHID))) AND (ehrprgtype.WHID <>-1)
   AND (ct.ServiceFK NOT IN (1, 19, 31, 49, 64, 83, 85, 86, 87, 111, 131, 
                             133, 134, 137, 139, 
        140, 141, 165, 167, 168, 171, 173, 174, 175, 198, 436, 442, 443, 
                          503, 522, 540, 541))

 GROUP BY 
          ehrrgn.WHID 
        , ehrrgn.EHRRegion 
        , ehrprgtype.WHID  
        , ehrprg.WHID 
        , ehrprg.EHRProgramCode
        , ehrprg.EHRProgramName 
        , poswh.WHID 
        , poswh.PositionNameWH
        , posfamwh.WHID 
        , posfamwh.PositionFamilyNameWH
        , pos.WHID 
        , empl.EmployeeCode
        , empl.EmployeeName
        , ct.ServiceDate
        , dd.YearMonthSort
        , ct.StaffFK 
        , tt.Total

为什么在SSRS中他们跳得那么高?

这是我的SSRS“设计”:

enter image description here

这是SSRS中的结果示例: 这些数字很高(用红色半圈圈出),但很小 (并在审核后更正)在SSMS(t-sql)中: enter image description here

请提供帮助或建议!

PS- 您可以点击图片放大查看

0 个答案:

没有答案