2015-08-31 2 views
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 

) С

ответ

1

plan и current оба reserved keywords.
Вам нужно будет с
select C.trandate, C.[plan], C.[current] from
или выберите другие названия.

+0

Спасибо - это сработало! – stackuser

Смежные вопросы