これに関する他の同様の質問を確認しましたWhere
が、クエリに句がないため、解決方法について少し混乱しています。
INSERT INTO #tmpCombined
SELECT A.Region
, 'MyLocation' AS 'Location'
, c.Id AS 'CompID'
, c.Name AS 'CompName'
, 'Cash' AS 'Context'
, isnull( sum( CASE WHEN T.TranAge >= 0 and CASE WHEN T.TranAge < 1 THEN 1 ELSE 0 END,0 )) AS 'ZeroDays0'
, isnull( sum( CASE WHEN T.TranAge >= 1 and CASE WHEN T.TranAge < 8 THEN 1 ELSE 0 END ), 0 ) AS '1to7Days'
, isnull( sum( CASE WHEN T.TranAge >= 8 and CASE WHEN T.TranAge < 16 THEN 1 ELSE 0 END ), 0 ) AS '8to15Days'
, isnull( sum( CASE WHEN T.TranAge >= 16 and CASE WHEN T.TranAge < 20 THEN 1 ELSE 0 END ), 0 ) AS '16to20Days'
, isnull( sum( CASE WHEN T.TranAge >= 20 THEN 1 ELSE 0 END ), 0 ) AS '20DaysPlus'
, COUNT(1) AS 'Total'
, A.Level as 'Level'
, sum(T.USDDifference) AS 'USDRevaluation'
from MyLocation.dbo.Company C
inner join #tmpCashTBResults T on T.CompanyId = C.Id
inner join #tmpCashAccounts A on T.CompanyId = A.CompanyId
group by A.Region, C.Id, C.Name, A.Level