WITH RecursiveCTE AS (
-- Anchor member
SELECT TOP 1
[ID],
CAST([Amount] AS NUMERIC) AS [Amount],
CAST([Balance] AS NUMERIC) AS [Balance],
(SELECT TOP 1 [FixedValue] FROM [Settings] ORDER BY [ID] DESC) AS [Constant]
FROM [Transactions]
ORDER BY [ID] ASC
UNION ALL
-- Recursive member
SELECT
[ID] + 1 AS [ID],
CAST([Amount] * 0.8 AS NUMERIC) AS [Amount],
CAST(([Amount] * 0.8 - [Constant]) AS NUMERIC) AS [Balance],
[Constant]
FROM RecursiveCTE
WHERE [Balance] > 0
)
SELECT [ID], [Balance]
FROM RecursiveCTE
ORDER BY [ID] ASC;
it gives the following error
sql parser error: Expected: ), found: UNION at Line: 11, Column: 5
Hi, the following is a valid MSSQL syntax
When parsed with the
sql-parser-rs
it gives the following error
https://learn.microsoft.com/en-us/sql/t-sql/queries/with-common-table-expression-transact-sql