0

我正在尝试在 SSMS 2014 中执行以下查询。但是,我无法从外部查询访问使用内部查询中的 case 语句创建的列。即我无法访问 c.current。获得错误 - C 附近的语法不正确

select C.trandate,C.plan,C.current from
(SELECT d.trandate,p.plan,
 case when datediff(dd,trandate,getdate()) <=30 then d.amount else 0 end as  'Current',
 case when datediff(dd,trandate,getdate()) between 31 and 60 then d.amount else 0 end as '31 to 60',
 case when datediff(dd,trandate,getdate()) between 331 and 360 then d.amount else 0 end as '331 to 360',
 case when datediff(dd,trandate,getdate()) > 360 then d.amount else 0 end as '>360',d.residentsys
FROM [HMXals_Reporting].[dbo].[TranARDetail] d
join [HMXals_Reporting].[dbo].[plans] p
on d.transys = p.plansys

) C

4

1 回答 1

1

plan并且current都是保留关键字
您必须
select C.trandate, C.[plan], C.[current] from
选择其他名称或选择其他名称。

于 2015-08-31T21:13:50.003 回答