如何修复我在下面的查询中遇到的语法错误?
SELECT
SUBSTRING (A. columnname 2,3) Alias
,SUBSTRING(A.columnname, 7,10) Alias2
FROM Tablename A
left join Tablename B on B.YR = 2017
AND A.columnname = SUBSTRING(b.Columnname 2,3)
CASE
WHEN B.columnname = 5 THEN 5
WHEN A.columnname <>'NA' THEN SUBSTRING(B. Columnname 2,3)
END AS First_Quater
INTO ##Results2017
GROUP BY SUBSTRING (A. columnname 2,3) Alias,
SUBSTRING(A.columnname, 7,10) Alias2,First Quater