.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> SQL Query >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Spliting Columns Using UNION ALL in SQL Server

Posted By:Shashi Ray       Posted Date: June 15, 2010    Points: 10    Category: SQL Query    URL: http://www.dotnetspark.com  

To display the required columns of two tables in a Sequence order through sql query
 

TABLE_1

C1 C2 C3 C4 C5 C6 C7 C8 C9 C10
A B C D E F G H I J

TABLE_2

B1 B2 B3 B4 B5 B6 B7 B8 B9 B10
1 2 3 4 5 6 7 8 9 10

C1 to C10 and B1 to B10  is a Column Name
RESULT

A B C D E
1 2 3 4 5
F G H I J
6 7 8 9 10

select C1,C2,C3,C4,C5 FROM TABLE_1 UNION ALL select B1,B2,B3,B4,B5 FROM TABLE_2 UNION ALL select C6,C7,C8,C9,C10 FROM TABLE_1 UNION ALL select B6,B7,B8,B9,B10 FROM TABLE_2 

 
Shashi Ray & Nidhi Sharma



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend