Issue with Window Function in SQL Server 2008 R2

后端 未结 2 818
别那么骄傲
别那么骄傲 2020-12-10 20:51

I get an execution error in following SQL script:

SELECT TOP 1 PERCENT
    a.accode, a.voucherdate, a.credit, a.Debit,
    SUM(a.Debit) OVER (ORDER BY [a.acco         


        
2条回答
  •  囚心锁ツ
    2020-12-10 21:34

    The problem is that you need SQL Server 2012 and above. Okay, I added the "and above" for future visitors, but compare 2008 OVER CLAUSE with 2012 OVER CLAUSE.

    The 2008 version has this important note:

    When used in the context of a ranking window function, can only refer to columns made available by the FROM clause. An integer cannot be specified to represent the position of the name or alias of a column in the select list. cannot be used with aggregate window functions.

提交回复
热议问题