THIS CODE NOT WORKING GIVING ERROR
Msg 102, Level 15, State 1, Line 2 Incorrect syntax near 'order'.
SELECT Id, StudentName, StudentGender, StudentAge, SUM (StudentAge) OVER (ORDER BY Id) AS RunningAgeTotal FROM Students
Hi Pawan4u,
Remember not all database systems support ORDER BY in the OVER clause of a window aggregate function.
SQL Server didn't support it until the latest version SQL Server 2012.
So you need to use PARTITION BY.
SELECT Id, StudentName, StudentGender, StudentAge, SUM (StudentAge) OVER (PARTITION BY ID) AS RunningAgeTotal FROM Students
Refer below link for more details.
https://docs.microsoft.com/en-us/sql/t-sql/queries/select-over-clause-transact-sql?view=sql-server-2017
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.