我已經查看了其他類似的問題,但我在查詢中沒有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
說,除了第一'isnull'行語法錯誤做的'不正確的位置)'。 – Oded
謝謝Vikdor,我應該認識到這一點!感謝Oded也。 – user1773949