0

我正在运行以下查询:-

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 行关键字“as”附近的语法不正确。

今天一定是漫长的一天,因为对于我的生活,我看不出它有什么问题???

别人能看出来吗???

4

2 回答 2

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)
于 2013-06-12T15:55:43.417 回答
1

必须从分组中取出“总和”和“月份”。

见下文:-

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
于 2013-06-12T16:02:18.270 回答