简体   繁体   English

每月SSRS报告,包含3列

[英]SSRS Report per month with 3 Columns count

I am working on SSRS report where I have 3 dates to deal with and get the count of each column per month starting September. 我正在处理SSRS报告,其中有3个日期要处理,并从9月开始每月获取每个列的计数。 Here is an image of what I am trying to achieve and I am not sure of what exactly I am missing in the Groupings. 这是我要实现的目标的图像,我不确定分组中到底缺少什么。 Any help would be really appreciated. 任何帮助将非常感激。 Query - 查询-

SELECT  CONVERT(NVARCHAR(10), TableA.DueDate, 101) AS DueDate ,
        CONVERT(NVARCHAR(10), TableB.DateFrom, 101) AS DateFrom ,
        CONVERT(NVARCHAR(10), TableB.DateTo, 101) AS DateTo
FROM    dbo.TableA
        INNER JOIN dbo.TableB ON dbo.TableA.Id = dbo.TableB.TableAid
WHERE   ( TableA.DueDate BETWEEN '2015-08-01'
                         AND     '2016-07-30' )
        AND ( TableB >= '08/01/2013' )
        AND ( TableB <= '07/30/2014' )

在此处输入图片说明

Its a little ugly but will get you the intended results - Just paste your query inside the definition of the CTE - 它有点难看,但可以为您带来预期的结果-只需将查询粘贴到CTE的定义中-

WITH DateCTE AS (SELECT
        DueDate, DateFrom, DateTo FROM DateTable)

SELECT MONTH, SUM(DueDate), SUM(DateFROM), SUM(DateTo)
FROM (
  SELECT DateName(month,DueDate) MONTH, Count(*) AS DueDate, 0 DateFROM , 0 DateTo
  FROM DateCTE 
  GROUP BY DateName(month,DueDate)
  UNION
  SELECT DateName(month,DateFrom) MOntH, 0 AS DueDate, COUNT(*) DateFROM , 0 DateTo
  FROM DateCTE 
  GROUP BY DateName(month,DateFrom)
  UNION
  SELECT DateName(month,DateTo) Month, 0 AS DueDate, 0 DateFROM , COUNT(*)  Dateto
  FROM DateCTE 
  GROUP BY DateName(month,DateTo)) UnionTable
GROUP BY MONTH

Heres the SQL fiddle - http://sqlfiddle.com/#!6/0a639/10 继承人的SQL小提琴- http://sqlfiddle.com/#!6/0a639/10

Ankit Khetan, What you're displaying in your report layout is an SSRS MATRIX format (like excel). Ankit Khetan,您在报表布局中显示的是SSRS MATRIX格式(例如excel)。 See if this works you instead of using a another query .... In your Select Statements extract the month number for each date variable. 看看这是否对您有用,而不是使用其他查询...。在“选择语句”中提取每个日期变量的月数。 Then try to use these numbers as your columns. 然后尝试将这些数字用作列。 and use your Date variables as your rows in the matrix layout. 并将Date变量用作矩阵布局中的行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM