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 2000 Forums
 Transact-SQL (2000)
 Retrieve, Compare & insert data from 3 different tables

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-11-09 : 07:08:33
Lector writes "Below is the description for the problem –

I have a Central Database table
I have Dim_CM – Consumer_Key table
I have a consumer information table – Consumer_Inf table
I have Dim_VIN – VIN_Key table
I have VIN information table – VIN_Inf table
I have Com_VIN table – Consumer_VIN_Inf table
The Central Database has two columns – C_key and V_Key
Consumer_Key table has CR_Key and Con_Key columns
Consumer_Inf table has Master_Id and CRef_Key columns
VIN_Key table has VR_Key and VK_KEY columns
VIN_Inf table has VIN_Id and VRef_Key columns

I have to get the Master_Id from Consumer_Inf table where CRef_Key from Consumer_Inf table = CR_Key from Consumer_Key table and this CR_Key should correspond to Con_Key where Con_Key = C_Key of Central database.

I have to get the VIN_Id from VIN_Inf table where VRef_Key from VIN_Inf table = VR_Key from VIN_Key table and this VR_Key should correspond to VK_Key where VK_Key = V_Key of Central database.

Now the result from the above two queries needs to be compared with Consumer_VIN_Inf table and if those results are not present in that table (row basis but not individual values)then they need to be inserted into a different table."

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-09 : 07:22:30
General Approach
Insert into yourTable(columns)
Select T1.col,T2.col,T3.col from Table1 T1 inner join Table2 T2 on T1.keycol=T2.keycol
inner join Table3 on T1.keycol=T3.keycol




Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -