コードのフォーマットが重要です:
SELECT SUM(net) AS net
FROM (
SELECT SUM(FB.[Net]) as net
FROM ((
[table1 AS FB
INNER JOIN Date
ON FB.DateKey = Date.DateKey
)
inner join [Store]
on [Store].StoreKey = FB.StoreKey
)
WHERE (FullDate BETWEEN DATEADD(WEEK, -12, CONVERT(date, GETDATE()))
AND DATEADD(day, -1, CONVERT(date, GETDATE()))
AND SName = 'XYZ'
AND DayNameOfWeek = 'Monday')
GROUP BY FB.[Net]
)
私は今、多くのエラーを見ることができます。これでほとんどの構文エラーが解決すると思いますが、希望する結果が得られるかどうかはわかりません。
SELECT SUM(net) AS net
FROM (
SELECT SUM([Net]) as net
FROM (
SELECT FB.net
FROM table1 AS FB
INNER JOIN [Date]
ON FB.DateKey = [Date].DateKey
inner join [Store]
on [Store].StoreKey = FB.StoreKey
WHERE FullDate BETWEEN DATEADD(WEEK, -12, GETDATE()) AND DATEADD(day, -1, GETDATE())
AND SName = 'XYZ'
AND DayNameOfWeek = 'Monday'
GROUP BY FB.[Net]
) A
) B
編集これは、構文エラーのない独自のコードです (私が知る限り)。次のコードは、同じ結果セットを提供する必要があります。
SELECT SUM(DISTINCT FB.net)
FROM table1 AS FB
INNER JOIN [Date]
ON FB.DateKey = [Date].DateKey
INNER JOIN [Store]
ON [Store].StoreKey = FB.StoreKey
WHERE FullDate BETWEEN DATEADD(WEEK, -12, GETDATE()) AND DATEADD(day, -1, GETDATE())
AND SName = 'XYZ'
AND DayNameOfWeek = 'Monday'
これでよろしいですか?