Create a view from two tables having different number of Columns
-
2012年5月7日 上午 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
- 已編輯 devROGUE 2012年5月7日 上午 07:21
所有回覆
-
2012年5月7日 上午 07:49解答者
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
- 已提議為解答 Ed Price - MSFTMicrosoft Employee, Owner 2012年5月7日 下午 05:57
- 已標示為解答 Ed Price - MSFTMicrosoft Employee, Owner 2012年5月7日 下午 06:27
-
2012年5月7日 下午 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- 已提議為解答 Ed Price - MSFTMicrosoft Employee, Owner 2012年5月7日 下午 05:56
-
2012年5月7日 下午 05:57擁有者
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)
-
2012年5月7日 下午 06: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 -
2012年5月7日 下午 06: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.