I want to union the results sets from the following CTEs so that I get 4 rows of data.
Id Name
-------------
1 Test1
2 Test2
3 Test3
4 Test4
The Sql I want to use is as follows
;with CTE1 (Id,Name)
as
(
select 1 as Id, 'Test1' as Name
union all
select 2, 'Test2'
)
select * from CTE1
union all
;with CTE2 (Id,Name)
as
(
select 3 as Id, 'Test3' as Name
union all
select 4, 'Test4'
)
select * from CTE2
However, I am getting a syntax error suggesting I can not use Union All between the two CTEs. How can I go around this?