glthornton
Programmer
Hi, I'm trying to compare 2 separate DB (SQL 2000 Server) tables to determine which Medical Record numbers are missing. I've developed a query to do that and it executes successfully, but I am not getting the end result that I am anticipating. Here is my query:
If I run each query separately, I get the expected results from each table/DB. I was curious to know if my 'NOT EXISTS' has problems comparing one 'VarChar' field to another? The MR_NUMBER field is defined as VarChar 11 and the id.value field is defined as VarChar 255. Can someone please let me know what I could be doing wrong here? For this query to work properly, I am expecting to get a result of about 924 MR_NUMBERS.
Any and all assistance would greatly be appreciated. Cheers, Glenn
Code:
SELECT DISTINCT MR_NUMBER
FROM OPENDATASOURCE('SQLOLEDB','Data Source=MAH-SQL1;User ID=sa;Password=').EHRSQL.dbo.od_ar_demographics
WHERE NOT EXISTS (SELECT DISTINCT id.value
FROM OPENDATASOURCE('SQLOLEDB','Data Source=MAH-ORION;User ID=sa;Password=').empi.dbo.patient pt INNER JOIN OPENDATASOURCE('SQLOLEDB','Data Source=MAH-ORION;User ID=sa;Password=').empi.dbo.name nm ON pt.uniqueid=nm.patientid INNER JOIN OPENDATASOURCE('SQLOLEDB','Data Source=MAH-ORION;User ID=sa;Password=').empi.dbo.identifier id ON nm.patientid=id.patientid
WHERE id.assigningauthnamespace='MRN' AND ISNUMERIC(id.value)=1 AND id.value <>'.')
If I run each query separately, I get the expected results from each table/DB. I was curious to know if my 'NOT EXISTS' has problems comparing one 'VarChar' field to another? The MR_NUMBER field is defined as VarChar 11 and the id.value field is defined as VarChar 255. Can someone please let me know what I could be doing wrong here? For this query to work properly, I am expecting to get a result of about 924 MR_NUMBERS.
Any and all assistance would greatly be appreciated. Cheers, Glenn