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.
| Author |
Topic |
|
inbs
Aged Yak Warrior
860 Posts |
Posted - 2010-06-28 : 03:49:06
|
| i have 3 tableTable 1.Customer IN Stage_Area DBTable 2.Customer IN DWHTable 3.TblPK hold the primary key (PK)1.Customer :A(PK),B(PK),C,D2.Customer :A(PK),B(PK),C,D3.TblPK :PK,TableName i want to JOIN between 1.Customer join 2.Customer ON TblPKhow can i do it? like that:SELECT * FROM Stage_Area.dbo.Customer a JOIN DWH.dbo.Customer b ON a.(SELECT PK FROM TblPK )=b.(SELECT PK FROM TblPK ) |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-06-28 : 04:45:22
|
| Can you provide some sample data ? |
 |
|
|
inbs
Aged Yak Warrior
860 Posts |
Posted - 2010-06-28 : 04:57:12
|
| [code]CUSTOMERA B C D1 10 AA X2 20 BB YTblPKPK TableNameA CUSTOMERB CUSTOMER[/code]i want that in ON will dynamicSELECT * FROM Stage_Area.dbo.Customer aJOIN DWH.dbo.Customer b ON a.A=b.A AND a.B=b.B |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-06-28 : 05:50:46
|
quote: Originally posted by inbsi want that in ON will dynamic
Why?Does there exists multiple relatioships between the two tables?Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH |
 |
|
|
inbs
Aged Yak Warrior
860 Posts |
Posted - 2010-06-28 : 06:51:33
|
| yes ,the pk composite from multiple columns |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-06-28 : 07:05:48
|
| Declare @var as varchar(max)='your on clause'Exec(SELECT * FROM Stage_Area.dbo.Customer aJOIN DWH.dbo.Customer b ' + @var)Make sure you have proper and matching aliases set for both the query and the dynamic ON clauseLimitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH |
 |
|
|
|
|
|