带日期范围的SSRS报告是可选的

时间:2013-09-05 00:04:30

标签: sql reporting-services

我目前正尝试使用包含日期范围(DateTO和DateFrom)的过滤器构建报表。问题是报告需要具有日期范围的能力作为可选。以下是我目前的SQL。请告知我如何修改

SELECT 

PG.Name AS [Project Group],
PSG.Name AS [Project Sub Group],
P.ReferenceNumber,
P.ReferenceNumber + ' / ' + P.ProjectTitle AS [Project Description],
CASE WHEN W.Removed = 1
 THEN 'Yes'
 ELSE 'No'
END AS [Removed],
W.Description,
W.CommunicationStartDate,
PR.Name as [Person Responsible],


CASE WHEN W.CommunicationStartDate IS NULL
 THEN 'Not Specified'
 ELSE CONVERT(NVARCHAR, W.CommunicationStartDate, 103)
END AS [Deadline],
ES.Name AS [Status],
CASE WHEN W.Estimate IS NOT NULL
 THEN W.Estimate
 ELSE 0
END AS [Estimate]

FROM dbo.ProjectWorkplan W
  INNER JOIN dbo.Project P
   INNER JOIN dbo.ProjectSubGroup PSG
   INNER JOIN dbo.ProjectGroup PG ON PSG.ProjectGroupId = PG.ProjectGroupId
  ON P.ProjectSubGroupId = PSG.ProjectSubGroupId
 ON W.ProjectId = P.ProjectId
 INNER JOIN dbo.PersonResponsible PR ON W.PersonResponsibleId = PR.PersonResponsibleId
 INNER JOIN dbo.ElementStatus ES ON W.ElementStatusId = ES.ElementStatusId

WHERE P.DateCompleted IS NULL AND W.Removed = 0
AND W.CommunicationStartDate BETWEEN @DateFrom AND @DateTo


AND ES.NAME in (@ActionRequired, @FollowUp, @OnHold, @UrgentAction, @Waiting,@Complete)


ORDER BY PG.Name, PSG.Name, P.ReferenceNumber, W.Removed, W.CommunicationStartDate

1 个答案:

答案 0 :(得分:0)

您可以检查NULL的日期参数,如果只有两个都有效,则使用它们:

AND (@DateFrom IS NULL OR @DateTo IS NULL OR W.CommunicationStartDate BETWEEN @DateFrom AND @DateTo)