Error message
The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP, OFFSET or FOR XML is also specified.
Code:
SELECT *
FROM
(SELECT
t.[Statement_ID], t.[InvoiceID],
t.S_Type as Type, t.Description, t.Date,
t.Debit, t.Credit, b.Balance
FROM
Statement as t
CROSS apply
(SELECT Balance = SUM(Debit) - SUM(Credit)
FROM Statement as x
WHERE (x.date < t.date or x.date = t.date and x.[Statement_ID] <= t.[Statement_ID] )
AND x.CustID = t.CustID ) b
WHERE
t.CustID = '48'
AND date between '2015-01-01' AND '2016-01-01'
ORDER BY
t.date)
ORDER BY
InvoiceID, Statement_ID
Move first ORDER BY to the end: