| Author |
Topic |
|
dr223
Constraint Violating Yak Guru
444 Posts |
Posted - 2010-05-27 : 12:04:30
|
| Hi, I have two databases namely GPDb and XPDb. I want to link a table called tblImport in XPDb to table called TblImport2 in GPDb. Both tables have a common field called GPID. Therefore is it possible to then write a query/view in XPDb to be able to read certain fields from GPDb when XPDb.TblImport2.GPID = GPDb.TblImport.GPIDAny help please Thanks |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-05-27 : 12:11:54
|
| select t2.<cols>,t1.<cols>from [GPDB].[owner].TblImport2 t2inner join [XPDB].[owner].tblImport t1on t2.GPID = t1.GPIDEveryday I learn something that somebody else already knew |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2010-05-27 : 12:12:57
|
| Yes, use 3 part joins or even 4 if they are on different servers:SELECT <yourfields> FROM <localtable> AS LTJOIN <linkedserver>.<database>.<schema>.<tablename> As RTON RT.<joinfield> = LT.<joinfield> |
 |
|
|
dr223
Constraint Violating Yak Guru
444 Posts |
Posted - 2010-05-27 : 12:23:04
|
| select t2.<cols>,t1.<cols>I am confused with the above statement, lets say you want to select fields gender, weight and height from TblImport2 in GPDb and also select field age from TblImport in XPDb.. Will it be select t2.<gender, weight, height>, t1.<age>Thanks |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-05-27 : 12:42:12
|
| sorry for the confusion, Use t2.gender,t2.weight,t2.height,t1.ageJimEveryday I learn something that somebody else already knew |
 |
|
|
dr223
Constraint Violating Yak Guru
444 Posts |
Posted - 2010-05-28 : 05:03:21
|
| Ok, I have a sample of the databases and fields as shown in the code below. select t2.GPRDPracID, t2.address1,t1.GPRDPracIDfrom [GPRDTech].[gprdsql].TblPracDetails t2inner join[Verisis].[dbo].tblImport t1ont2.GPRDPracID = t1.GPRDPracIDI am running it in Verisis database and receive the error, Msg 207, Level 16, State 1, Line 6Invalid column name 'GPRDPracID'.Msg 207, Level 16, State 1, Line 1Invalid column name 'GPRDPracID'.However, GPRDPracID is a common field in both tables. Any help please |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-28 : 05:19:43
|
is gprdsql a schema? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
dr223
Constraint Violating Yak Guru
444 Posts |
Posted - 2010-05-28 : 06:16:18
|
| yes GPRDTech has gprdsql as the schema and Verisis dbo.. Thanks |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-28 : 07:55:46
|
Then be sure there is no slight difference in spelling the column names. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|