declare @MyTable table (id int)
insert @MyTable values (1),(2),(3),(4),(5);
with cte(id,i) as
(select m.ID , 1 from @MyTable m union all
select ID , cte.i +1 from cte where cte.i < 5)
select * from cte
Sql Server: cte query with outer table
-
17-07-2023 - |
سؤال
i have this code:
with cte as
(select m.ID , 1 i from MyTable m union all
select ID , cte.i +1 i from cte where i < 5)
select * from cte
error message: Msg 319, Level 15, State 1, Line 2 Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
What is wrong?
المحلول
لا تنتمي إلى StackOverflow