SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Create view with multiple tables
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dan963
Starting Member

United Kingdom
3 Posts

Posted - 04/29/2012 :  12:26:47  Show Profile  Reply with Quote
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

India
47188 Posts

Posted - 04/29/2012 :  12:40:09  Show Profile  Reply with Quote

insert TableA
select 'IDDate',IDDate
from tableB
union all
select 'Notified',Notified
from tableB
union all
select 'Detail',Detail
FROM tableC


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

United Kingdom
3 Posts

Posted - 04/29/2012 :  12:53:04  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000