Answered by:
Create a view from two tables having different number of Columns

Question
-
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 7, 2012 7:21 AM
Monday, May 7, 2012 7:17 AM
Answers
-
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 Monday, May 7, 2012 5:57 PM
- Marked as answer by Ed Price - MSFTMicrosoft employee Monday, May 7, 2012 6:27 PM
Monday, May 7, 2012 7:49 AMAnswerer
All replies
-
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 Monday, May 7, 2012 5:57 PM
- Marked as answer by Ed Price - MSFTMicrosoft employee Monday, May 7, 2012 6:27 PM
Monday, May 7, 2012 7:49 AMAnswerer -
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 Monday, May 7, 2012 5:56 PM
Monday, May 7, 2012 12:44 PM -
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 7, 2012 5:57 PM -
Sure, 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 blogMonday, May 7, 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.
Monday, May 7, 2012 6:13 PM