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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Create view with multiple tables

Author  Topic 

dan963
Starting Member

3 Posts

Posted - 2012-04-29 : 12:26:47
Hi,
I have 3 tables and I'm trying to merge data from all 3 tables into a 2 column view and if anyone can help that would be great. I want the column names from Table B and Table C to be entered into the Field column in Table A and the rows from Table B and Table C to be entered into Table A's Value column.

Table A: (2 column field and value)

Details Value
ID 1
Employee No 123456
Leaving Date 01-05-2012
Leaving Reason 11

Table B: (2 columns)

IDDate Notified
01-04-2012

Table C: (a lookup table for Leaving Reason)

Detail
Early Retirement

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-29 : 12:40:09
[code]
insert TableA
select 'IDDate',IDDate
from tableB
union all
select 'Notified',Notified
from tableB
union all
select 'Detail',Detail
FROM tableC
[/code]

I hope there's a column which is common across tables by which you link it, but you've not shown it in example above. in that case you need to include that column also in inserts

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dan963
Starting Member

3 Posts

Posted - 2012-04-29 : 12:53:04
Thanks for the reply. I accidently posted it without putting all the info. If you could look at the other post I posted shortly afterwards, it has all the correct info.
Thanks again
Go to Top of Page
   

- Advertisement -