65.9K
CodeProject is changing. Read more.
Home

UNION ALL between Two CTEs

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.86/5 (7 votes)

Aug 26, 2010

CPOL
viewsIcon

31394

Hello, Folks You may Have tried to Apply Union All betwenn two CTEs. For Example, If you Have two Tables Named TableA and TableB
WITH CTE_TableA
AS
(
SELECT * FROM TableA
)

UNION ALL

WITH CTE_TableA
AS
(
SELECT * FROM TableA
)
Then Above SQL Statement Will be result into Error. Now To Make Union Of Two CTEs, Follow Below Code Snippets,
WITH CTE_TableA
AS
(
SELECT * FROM TableA
),CTE_TableB
(
SELECT * FROM TableB
)

SELECT * FROM CTE_TableA
UNION ALL
SELECT * FROM CTE_TableB
Happy Coding !!!