我正在尝试使用我在查询中创建的列别名,在同一查询中的公式内用于不同的列。我在这里做错了什么,我该如何解决?这里的代码可以更好地解释自己:
SELECT TestTabI.Month, TestTabI.Year, AccessEntityList.Region,
AccessEntityList.[Audit Tier], AccessEntityList.[Parent Group],
case
when AccessEntityList.[Jurisdiction]='U.S.'
then [NF PTI]
else 0
end AS [US Pretax Income],
case
when AccessEntityList.[Jurisdiction]='Non-U.S.'
then [NF PTI]
else 0
end AS [FN Pretax Income],
[US Pretax Income]+[FN Pretax Income] AS [Total Pretax Income] FROM AccessEntityList
INNER JOIN TestTabI ON AccessEntityList.[Entity Number] =
TestTabI.[Entity Number] WHERE (((TestTabI.Month)=12) AND ((TestTabI.Year)=2010)
“ [US Pretax Income]+[FN Pretax Income] AS [Total Pretax Income] ”给了我错误:
Msg 207, Level 16, State 1, Line 7
Invalid column name 'US Pretax Income'.
Msg 207, Level 16, State 1, Line 7
Invalid column name 'FN Pretax Income'.