Create a view from two tables having different number of Columns
-
Monday, May 07, 2012 7:17 AM
Hi,
I want to construct a view in T-SQL by combining (like UNION ALL) two or more tables with different no. of columns.
Eg. TABLE1 contains 3 columns (all VARCHAR) and 2 rows, TABLE2 contains 4 columns (all VARCHAR) and 4 rows. I would like the resultant view to be of 4 columns and 6 rows by combining these two tables. Retaining column names is not important
PS : These tables are determined dynamically, so there is no way of knowing how many columns would be there beforehand. The only guarantee is that the ALL THE COLUMNS would be of the type VARCHAR
- Edited by devROGUE Monday, May 07, 2012 7:21 AM
All Replies
-
Monday, May 07, 2012 7:49 AMAnswerer
best ask in the T-SQL forum: http://social.technet.microsoft.com/Forums/en-US/transactsql/threads
this forum is mainly for profile and recognition system topics
- Proposed As Answer by Ed Price - MSFTMicrosoft Employee, Owner Monday, May 07, 2012 5:57 PM
- Marked As Answer by Ed Price - MSFTMicrosoft Employee, Owner Monday, May 07, 2012 6:27 PM
-
Monday, May 07, 2012 12:44 PM
If the tables are generated dynamically, perhaps you need to generate the view dynamically as well if it has to be a view.For every expert, there is an equal and opposite expert. - Becker's Law
My blog- Proposed As Answer by Ed Price - MSFTMicrosoft Employee, Owner Monday, May 07, 2012 5:56 PM
-
Monday, May 07, 2012 5:57 PMOwner
best ask in the T-SQL forum: http://social.technet.microsoft.com/Forums/en-US/transactsql/threads
this forum is mainly for profile and recognition system topics
DevRogue, let us know if you want us to move it there. Also, check out Naomi's answer and mark it if it helps you solve this issue. Thanks!Ed Price (a.k.a User Ed), SQL Server Experience Program Manager (Blog, Twitter, Wiki)
-
Monday, May 07, 2012 6:13 PMSure, please move it there and also please merge to his other thread which is the same and already answered.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog -
Monday, May 07, 2012 6:13 PM
I created a new thread on the tsql forum..
and i also got an answer there..
so please delete this thread..
Sorry for the inconvenience.

