Click here to Skip to main content
11,481,760 members (59,897 online)
Click here to Skip to main content

Tagged as

UNION ALL between Two CTEs

, 27 Aug 2010 CPOL 9K 5
Rate this:
Please Sign up or sign in to vote.
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 !!!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Hiren solanki
Software Developer
India India
He is a Smart IT devloper with Few years of Expeariance But having Great command on ASP.net,C#,SQL Query,SSRS,Crystal Reports

Apart from that He Loves multimedia work too, Master of Adobe photoshop, Illustrator, CSS , HTML and all things.

He is Currently working in Microsoft Dynamics CRM and Having Nice Expearince with CRM. CRM Rocks!!!

Comments and Discussions

 
GeneralReason for my vote of 5 Good Example. Pin
NMehta8321-Sep-10 20:44
memberNMehta8321-Sep-10 20:44 
GeneralThanks for your comment @linuxjr Pin
Hiren Solanki29-Aug-10 21:33
memberHiren Solanki29-Aug-10 21:33 
GeneralReason for my vote of 5 Thanks for sharing this tip. Pin
linuxjr29-Aug-10 8:12
memberlinuxjr29-Aug-10 8:12 
GeneralThanks, Small but nice Tip/Trick. Pin
Hiren Solanki26-Aug-10 20:47
memberHiren Solanki26-Aug-10 20:47 
GeneralReason for my vote of 5 good one.. Pin
Sandeep Ramani26-Aug-10 20:42
memberSandeep Ramani26-Aug-10 20:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 27 Aug 2010
Article Copyright 2010 by Hiren solanki
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid