glthornton
Programmer
Hi everyone, I'm working with 2 different SQL DB's on 2 separate servers running SQL 2000. What I am trying to do is extract diabetic patients from 1 DB based upon a zip code listing which is in another DB on a separate server. Here is the select statement that I've put together thus far:
As you can see at the end of the WHERE statement, that I am trying to do the comparison of the patients zip code (pts.zipcode) to that of the values it has stored in the other DB table on the other server. Can anyone point me in the right direction as to getting this to work? I have not worked with cross-linking databases like this before.
Any and all assistance would greatly be appreciated.
Kind Regards,
glthornton
Code:
SELECT DISTINCT pts.lastname,pts.firstname,vst.patientlastname,vst.patid,pts.statuscode
FROM Patients pts INNER JOIN Visits vst ON pts.patid = vst.PatID
INNER JOIN Assessments assess ON assess.vid = vst.vid
WHERE ((assess.Icd9Code = '250.00' or
assess.Icd9Code = '250.01'or
assess.Icd9Code = '250.02'or
assess.Icd9Code = '250.03'or
assess.Icd9Code = '250.01'or
assess.Icd9Code = '250.8'or
assess.Icd9Code = '250.82'or
assess.Icd9Code = '250.83'or
assess.Icd9Code = '251.8'or
assess.Icd9Code = '253.5'or
assess.Icd9Code = '790.2'or
assess.Icd9Code = '790.29') and (pts.statuscode <> '32768' and pts.statuscode <> '33025') and
(vst.patientlastname<>'Test' and
vst.patientlastname<>'' and
vst.patientlastname<>'Barber' and
vst.patientlastname<>'Milek' and
vst.patientlastname<>'Nichols' and
vst.patientlastname<>'Thatcher') and
(pts.zipcode like SELECT *
FROM OPENDATASOURCE('SQLOLEDB','Datasource=MAH-SQL1;User ID=sa;Password=').VTCCIS.dbo.VTDiabeticZC)))
ORDER BY pts.lastname,pts.firstname
As you can see at the end of the WHERE statement, that I am trying to do the comparison of the patients zip code (pts.zipcode) to that of the values it has stored in the other DB table on the other server. Can anyone point me in the right direction as to getting this to work? I have not worked with cross-linking databases like this before.
Any and all assistance would greatly be appreciated.
Kind Regards,
glthornton