SQL to query different databases which are in different server instances

2011-05-01

EXEC sp_addlinkedserver
@server='S3',
@srvproduct='',
@provider='SQLOLEDB',
@datasrc='192.168.10.130',
@catalog ='WC+PRDMAINDBNEW'
EXEC sp_addlinkedsrvlogin 'S3', 'false', NULL, 'sa', 'atotestdb'

SELECT TBLWPAirlineOperatingSector.
FromSector,TBLWPAirlineOperatingSector.ToSector,TBL2.TaxFromSector,TBL2.TaxToSector FROM

(
SELECT FromSector,ToSector FROM S3.[WC+PRDMAINDBNEW].DBO.WPAirlineOperatingSector WHERE AirlineCode like '6E' AND LEN(FromSector)=3 AND LEN(ToSector)=3
) AS TBLWPAirlineOperatingSector
LEFT OUTER JOIN [ANS+CACHEDB].DBO.B2CAirlineTaxNRMCacheDOMIndigo AS TBL2
ON TBLWPAirlineOperatingSector.FromSector= TBL2.TaxFromSector AND
TBLWPAirlineOperatingSector.ToSector= TBL2.TaxToSector

0 comments: