我正在运行以下查询: -
SELECT
FISCALYEAR,
DATENAME(Month,JVDate) as Month,
ACCOUNTNUMBER,
ACCOUNTDESCRIPTION,
CATEGORY,
POSTINGTYPE,
sum(ORIGNETAMOUNT) as ORIGNETAMOUNT
FROM dbo.vw_GLTrialBalancev2010
INNER JOIN GL00100
ON GL00100.ACTNUMBR_1 = dbo.vw_GLTrialBalancev2010.SEGMENT1
AND GL00100.ACTNUMBR_2 = dbo.vw_GLTrialBalancev2010.SEGMENT2
group by FISCALYEAR,
DATENAME(Month,JVDate) as Month,
ACCOUNTNUMBER,
ACCOUNTDESCRIPTION,
CATEGORY,
POSTINGTYPE,
sum(ORIGNETAMOUNT) as ORIGNETAMOUNT
但是收到以下错误: -
消息156,级别15,状态1,行14关键字附近的语法不正确 '为'。
今天一定是漫长的一天,因为在我的生活中,我看不出它有什么问题?
其他人可以发现它????
答案 0 :(得分:1)
as
条款中不允许 group by
。试试这个:
SELECT
FISCALYEAR,
DATENAME(Month,JVDate) as Month,
ACCOUNTNUMBER,
ACCOUNTDESCRIPTION,
CATEGORY,
POSTINGTYPE,
sum(ORIGNETAMOUNT) as ORIGNETAMOUNT
FROM dbo.vw_GLTrialBalancev2010
INNER JOIN GL00100
ON GL00100.ACTNUMBR_1 = dbo.vw_GLTrialBalancev2010.SEGMENT1
AND GL00100.ACTNUMBR_2 = dbo.vw_GLTrialBalancev2010.SEGMENT2
group by FISCALYEAR,
DATENAME(Month,JVDate),
ACCOUNTNUMBER,
ACCOUNTDESCRIPTION,
CATEGORY,
POSTINGTYPE,
sum(ORIGNETAMOUNT)
答案 1 :(得分:1)
必须从分组中取出'sum'和'as Month'。
见下文: -
SELECT
FISCALYEAR,
DATENAME(Month,JVDate) as Month,
ACCOUNTNUMBER,
ACCOUNTDESCRIPTION,
CATEGORY,
POSTINGTYPE,
sum(ORIGNETAMOUNT) as ORIGNETAMOUNT
FROM dbo.vw_GLTrialBalancev2010
INNER JOIN GL00100
ON GL00100.ACTNUMBR_1 = dbo.vw_GLTrialBalancev2010.SEGMENT1
AND GL00100.ACTNUMBR_2 = dbo.vw_GLTrialBalancev2010.SEGMENT2
group by FISCALYEAR, DATENAME(Month,JVDate), ACCOUNTNUMBER,
ACCOUNTDESCRIPTION, CATEGORY, POSTINGTYPE