Create a view from two tables having different number of Columns
-
7 mai 2012 07:17
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
- Editat de devROGUE 7 mai 2012 07:21
Toate mesajele
-
7 mai 2012 07:49Membru care oferă răspunsuri
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
- Propus ca răspuns de Ed Price - MSFTMicrosoft Employee, Owner 7 mai 2012 17:57
- Marcat ca răspuns de Ed Price - MSFTMicrosoft Employee, Owner 7 mai 2012 18:27
-
7 mai 2012 12:44
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- Propus ca răspuns de Ed Price - MSFTMicrosoft Employee, Owner 7 mai 2012 17:56
-
7 mai 2012 17:57Proprietar
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)
-
7 mai 2012 18:13Sure, 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 -
7 mai 2012 18:13
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.