3

我有一個SSRS月度日曆,可以吸引您指定月份的所有日期,並且還顯示前一個月和下一個月的日期,以顯示6,7天周。我試圖現在要做的就是顯示每個星期範圍一個月,例如,在2015年11月我會想:6 SSRS日曆每個月的第7個星期日期範圍

Oct 25-31 
Nov 1-7 
Nov 8-14 
Nov 15-21 
Nov 22-28 
Nov 29-Dec 5 

我試圖建立槓桿看起來像表達以下內容:

="Week " & VBCRLF & Left(MonthName(Parameters!start_cymd.Value.Month,False),3) & " " & Fields!Day.Value & " - " & Fields!Day.Value + 6 

爲了得到我想要的結果,我應該做些什麼?如果您需要更多信息來回答我的問題,我很樂意提供。謝謝!

編輯:

電流輸出 enter image description here

存儲過程生成日曆:

ALTER PROCEDURE [Event].[Report_Event_Calendar_Month_sp] 
@start_cymd DATE = NULL 
AS 
BEGIN 

DECLARE @StartDate DATE = @start_cymd , 
     @EndDate DATE = @start_cymd , 
     @SDate DATE = @start_cymd 

---First day of current month 
SET @StartDate = DATEADD(s, 0, DATEADD(mm, DATEDIFF(m, 0, @StartDate), 0)) 
SET @SDate = DATEADD(s, 0, DATEADD(mm, DATEDIFF(m, 0, @SDate), 0)) 
---First day to display on calendar 
SET @StartDate = DATEADD(DAY, -DATEPART(DAY, @StartDate) - 6, @StartDate) 
---Last day of month 
SET @EndDate = DATEADD(s, -1, DATEADD(mm, DATEDIFF(m, 0, @SDate) + 1, 0)) 
---Last day to display on calendar 
SET @EndDate = DATEADD(DAY, -DATEPART(DAY, @EndDate) + 35, @EndDate) 

;WITH Dates([Date]) 
     AS (
      SELECT @StartDate AS [Date] 
      UNION ALL 
      SELECT DATEADD(DAY, 1, [Date]) 
      FROM Dates 
      WHERE [Date] < @EndDate 
     ) , 
     Events 
     AS (
      SELECT EventDesc , 
        Notes , 
        start_cymd AS EventDate , 
        MemberName 
      FROM [Event].Event_Description ED 
        INNER JOIN [Event].SQL_Team_Events SE ON ED.EventDesc_ID = SE.EventDesc_ID 
        INNER JOIN [Event].SQL_Team_Member SM ON SE.Event_ID = SM.Event_ID 
        INNER JOIN [Event].Members M ON SM.Member_ID = M.Member_ID 
     ) 


---Number the records based on the date, if multiple records have 
    ---the same date then they will be numbered the same. Used in 
    ---calculation to determine row record is to display 
    SELECT [Order] = DENSE_RANK() OVER (ORDER BY d.[Date]) , 
    ---Date used in all calculations for date 
      d.[Date] , 
    ---Generates matrix columns 
      [WeekDay] = DATEPART(WEEKDAY, d.[Date]) , 
    ---Used to display day of month on calendar 
      [Day] = DATEPART(DAY, d.[Date]) , 
    ---Used in some calculations for display 
      [Month] = DATEPART(MONTH, d.[Date]) , 
      e.EventDesc , 
      e.Notes , 
      e.EventDate , 
      e.MemberName 
    FROM  Dates d 
      LEFT JOIN Events e ON d.[Date] = e.EventDate 
    ---Set the maximum number of times the CTE 'Dates' can recurse 
    OPTION (MAXRECURSION 100) 

END 
GO 
+1

您需要在表達式末尾有一個'IIF'函數來確定'Fields!Day.Value + 6'是否超過了月份的長度以使週中的月份更改顯示正確(* Nov 29 -Sep 5 *)。乍一看,其餘的對我來說似乎很好。 – Oceans

+0

是的......咖啡還沒有踢在大聲笑。 – postald

+0

是否有原因導致您無法使用SQL查詢在數據集中生成此信息?這讓我覺得很容易,尤其是當你考慮不同的月份長度,你將不得不處理 – Jonnus

回答

2

試試這個:

Reporting Services的表達

=Switch(
DatePart("D",Fields!Date.Value) + 6 > Datepart("D",Fields!Date.Value.AddDays(1-Fields!Date.Value.Day).AddMonths(1).AddDays(-1)), 
"Week" & VBCRLF & Left(MonthName(Fields!Date.Value.Month,False),3) & " " & DatePart("D",Fields!Date.Value) & " - " & 
Left(MonthName(Fields!Date.Value.Month + 1,False),3) & " " & DatePart("D",Fields!Date.Value.AddDays(6)), 
true, 
"Week" & VBCRLF & Left(MonthName(Fields!Date.Value.Month,False),3) & " " & DatePart("D",Fields!Date.Value) & " - " & 
DatePart("D",Fields!Date.Value.AddDays(6)) 
) 
  • 與2015年2月27日返回測試:測試與2015年11月29日返回Week feb 27 - mar 5
  • Week nov 29 - dec 5
  • 測試了2015年11月22日返回:Week nov 22 - 22

說明我正在使用的數據集中的字段Date對於Day

T-SQL

在T-SQL級別,你可以用你需要的數據添加列,然後在報告中表達串聯那些列。

SELECT [Order] = DENSE_RANK() OVER (ORDER BY d.[Date]) , 
---Date used in all calculations for date 
      d.[Date] , 
---Generates matrix columns 
      [WeekDay] = DATEPART(WEEKDAY, d.[Date]) , 
---Used to display day of month on calendar 
      [Day] = DATEPART(DAY, d.[Date]) , 
---Used in some calculations for display 
      [Month] = DATEPART(MONTH, d.[Date]) 
---New filds for rows expression in SSRS 
      ,LEFT(DATENAME(MONTH,d.[Date]),3) as [StartMonth] 
      ,DATEPART(DAY,d.[Date]) as [StartDay] 
      ,IIF(DATEADD(day,6,d.[Date]) > EOMONTH(d.[Date]) 
       ,LEFT(DateName(Month,DATEADD(day,6,d.[Date])),3) 
       ,'' 
       ) as [EndMonth] 
      ,Datepart(day,DATEADD(day,6,d.[Date])) as [EndMonth]    
      e.EventDesc , 
      e.Notes , 
      e.EventDate , 
      e.MemberName 
FROM  Dates d 
      LEFT JOIN Events e ON d.[Date] = e.EventDate 

表達:

= "Week" & VBCRLF & Fields!StartMonth.Value & " " & Fields!StartDay.Value & 
" - " & Fields!EndMonth.Value & " " & Fields!EndDay.Value 

讓我知道如果這能幫助你。

+0

這很完美!非常感謝! – postald

+0

@postald,很好!如果您的問題已被清除,您可以選擇我的答案爲正確的,只需點擊答案左側的正確符號即可。 –

相關問題