0

現在、日付範囲 (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
4

1 に答える 1

1

NULL の日付パラメーターを確認し、両方が有効な場合にのみ使用できます。

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

于 2013-09-05T01:47:31.063 に答える