以下のクエリの結果をフィルタリングするための支援が必要です。具体的にdbo.pertot_all.sort_method = 2
は、where句で指定されたすべての日付の結果のみを返す必要があります。現在、以下に提供されているものを使用して、他のsort_methodsを返します。AND/OR演算子の順序/グループ化に慣れていません。誰かがいくつかのガイダンスを提供できますか?よろしくお願いします。
SELECT dbo.SiteDescription.Site, dbo.SiteDescription.Description AS SiteDescription, dbo.SiteDescription.LocationGroup, dbo.chart_all.acct, dbo.pertot_all.sf2,
dbo.SSRS_sf2UnitCodes.sf2description, dbo.pertot_all.sf4, dbo.SSRS_sf4UnitCodes.sf4description, dbo.chart_all.description AS AccountDescription,
dbo.pertot_all.amt, dbo.pertot_all.per_start, dbo.pertot_all.sort_method
FROM dbo.SSRS_sf2UnitCodes INNER JOIN
dbo.pertot_all ON dbo.SSRS_sf2UnitCodes.sf2UnitCode = dbo.pertot_all.sf2 INNER JOIN
dbo.SSRS_sf4UnitCodes ON dbo.pertot_all.sf4 = dbo.SSRS_sf4UnitCodes.sf4UnitCode RIGHT OUTER JOIN
dbo.chart_all LEFT OUTER JOIN
dbo.SiteDescription ON dbo.chart_all.site_ref = dbo.SiteDescription.Site ON dbo.pertot_all.site_ref = dbo.SiteDescription.Site AND
dbo.pertot_all.sf1 = dbo.chart_all.acct
WHERE (1 = 1) AND (ISNULL(dbo.pertot_all.per_start, '2012-01-01 00:00:00.000') = '2012-01-01 00:00:00.000') AND (ISNULL(dbo.pertot_all.sort_method, 2) = 2) OR
(ISNULL(dbo.pertot_all.per_start, '2012-02-01 00:00:00.000') = '2012-02-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2012-03-01 00:00:00.000') = '2012-03-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2012-04-01 00:00:00.000') = '2012-04-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2012-05-01 00:00:00.000') = '2012-05-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2012-06-01 00:00:00.000') = '2012-06-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2012-07-01 00:00:00.000') = '2012-07-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2012-08-01 00:00:00.000') = '2012-08-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2012-09-01 00:00:00.000') = '2012-09-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2012-10-01 00:00:00.000') = '2012-10-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2012-11-01 00:00:00.000') = '2012-11-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2012-12-01 00:00:00.000') = '2012-12-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2011-01-01 00:00:00.000') = '2011-01-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2011-02-01 00:00:00.000') = '2011-02-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2011-03-01 00:00:00.000') = '2011-03-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2011-04-01 00:00:00.000') = '2011-04-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2011-05-01 00:00:00.000') = '2011-05-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2011-06-01 00:00:00.000') = '2011-06-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2011-07-01 00:00:00.000') = '2011-07-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2011-08-01 00:00:00.000') = '2011-08-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2011-09-01 00:00:00.000') = '2011-09-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2011-10-01 00:00:00.000') = '2011-10-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2011-11-01 00:00:00.000') = '2011-11-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2011-12-01 00:00:00.000') = '2011-12-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2010-01-01 00:00:00.000') = '2010-01-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2010-02-01 00:00:00.000') = '2010-02-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2010-03-01 00:00:00.000') = '2010-03-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2010-04-01 00:00:00.000') = '2010-04-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2010-05-01 00:00:00.000') = '2010-05-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2010-06-01 00:00:00.000') = '2010-06-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2010-07-01 00:00:00.000') = '2010-07-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2010-08-01 00:00:00.000') = '2010-08-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2010-09-01 00:00:00.000') = '2010-09-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2010-10-01 00:00:00.000') = '2010-10-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2010-11-01 00:00:00.000') = '2010-11-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2010-12-01 00:00:00.000') = '2010-12-01 00:00:00.000') OR
(ISNULL(dbo.pertot_all.per_start, '2009-12-01 00:00:00.000') = '2009-12-01 00:00:00.000')