Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Creating a view using a Union

Author  Topic 

scanpj10
Starting Member

1 Post

Posted - 2015-01-14 : 10:35:26
I am looking to create a new view by combining two tables, but i would like to create a new column in the view that identifies what table the data came from. For example I have a Table A and Table B, using a union i combined the two table but i want a new column titled Source which could be populated by A or B.

This is my code so far:
Create View Table_AB As
Select *From Table_A
Union All
Select*From Table_B

Any help would be greatly appreciated

mhorseman
Starting Member

44 Posts

Posted - 2015-01-14 : 11:17:26
Something like:

Create View Table_AB As
Select 'A' source,* From Table_A
Union All
Select 'B',* From Table_B


Mark
Go to Top of Page
   

- Advertisement -