Big Pat
06-17-2008, 07:18 AM
Hi,
Patients at our hospital can have up to 12 surgical procedures per episode. The fields are [Primary procedure], [2nd procedure], [3rd procedure] etc. For each record in my database, none, some or (rarely) all of these may contain codes like A999.
I need to find patients that have codes (like Q07* or like Q08*) AND have another code (like R17* or R18* or R21* or R22* or R24* or R251).
The problem is that these codes could be in any of the 12 fields and they may or may not have other codes too. So there could be a patient with Q072 as the [primary procedure] and R228 as [5th procedure], but equally there could be one with Q072 as [5th procedure], with R228 as [2nd procedure] and something else entirely as the [primary procedure]
This is all I have come up with so far. I didn't WRITE this SQL, but created my query in design view and then copied the SQL.
SELECT [tbl Inpatients & Daycases 2007_2008].[Discharge Date], [tbl Inpatients & Daycases 2007_2008].[Primary Procedure], [tbl Inpatients & Daycases 2007_2008].[2nd Procedure], [tbl Inpatients & Daycases 2007_2008].[3rd Procedure], [tbl Inpatients & Daycases 2007_2008].[4th Procedure], [tbl Inpatients & Daycases 2007_2008].[5th Procedure], [tbl Inpatients & Daycases 2007_2008].[6th Procedure], [tbl Inpatients & Daycases 2007_2008].[7th Procedure], [tbl Inpatients & Daycases 2007_2008].[8th Procedure], [tbl Inpatients & Daycases 2007_2008].[9th Procedure], [tbl Inpatients & Daycases 2007_2008].[10th Procedure], [tbl Inpatients & Daycases 2007_2008].[11th Procedure], [tbl Inpatients & Daycases 2007_2008].[12th Procedure], [tbl Inpatients & Daycases 2007_2008].[Episode Number], [tbl Inpatients & Daycases 2007_2008].[UR Number]
FROM [tbl Inpatients & Daycases 2007_2008]
WHERE ((([tbl Inpatients & Daycases 2007_2008].[Primary Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[Primary Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[2nd Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[2nd Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[3rd Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[3rd Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[4th Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[4th Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[5th Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[5th Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[6th Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[6th Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[7th Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[7th Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[8th Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[8th Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[9th Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[9th Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[10th Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[10th Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[11th Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[11th Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[12th Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[12th Procedure]) Like "Q08*"));
Of course, this just gives me the records with Q07 and Q08 codes, but I can't work out what to do next. My brain has run smack up against a brick wall.
I'd be really grateful for some help.
Thank you.
Patients at our hospital can have up to 12 surgical procedures per episode. The fields are [Primary procedure], [2nd procedure], [3rd procedure] etc. For each record in my database, none, some or (rarely) all of these may contain codes like A999.
I need to find patients that have codes (like Q07* or like Q08*) AND have another code (like R17* or R18* or R21* or R22* or R24* or R251).
The problem is that these codes could be in any of the 12 fields and they may or may not have other codes too. So there could be a patient with Q072 as the [primary procedure] and R228 as [5th procedure], but equally there could be one with Q072 as [5th procedure], with R228 as [2nd procedure] and something else entirely as the [primary procedure]
This is all I have come up with so far. I didn't WRITE this SQL, but created my query in design view and then copied the SQL.
SELECT [tbl Inpatients & Daycases 2007_2008].[Discharge Date], [tbl Inpatients & Daycases 2007_2008].[Primary Procedure], [tbl Inpatients & Daycases 2007_2008].[2nd Procedure], [tbl Inpatients & Daycases 2007_2008].[3rd Procedure], [tbl Inpatients & Daycases 2007_2008].[4th Procedure], [tbl Inpatients & Daycases 2007_2008].[5th Procedure], [tbl Inpatients & Daycases 2007_2008].[6th Procedure], [tbl Inpatients & Daycases 2007_2008].[7th Procedure], [tbl Inpatients & Daycases 2007_2008].[8th Procedure], [tbl Inpatients & Daycases 2007_2008].[9th Procedure], [tbl Inpatients & Daycases 2007_2008].[10th Procedure], [tbl Inpatients & Daycases 2007_2008].[11th Procedure], [tbl Inpatients & Daycases 2007_2008].[12th Procedure], [tbl Inpatients & Daycases 2007_2008].[Episode Number], [tbl Inpatients & Daycases 2007_2008].[UR Number]
FROM [tbl Inpatients & Daycases 2007_2008]
WHERE ((([tbl Inpatients & Daycases 2007_2008].[Primary Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[Primary Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[2nd Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[2nd Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[3rd Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[3rd Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[4th Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[4th Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[5th Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[5th Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[6th Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[6th Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[7th Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[7th Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[8th Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[8th Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[9th Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[9th Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[10th Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[10th Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[11th Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[11th Procedure]) Like "Q08*")) OR ((([tbl Inpatients & Daycases 2007_2008].[12th Procedure]) Like "Q07*" Or ([tbl Inpatients & Daycases 2007_2008].[12th Procedure]) Like "Q08*"));
Of course, this just gives me the records with Q07 and Q08 codes, but I can't work out what to do next. My brain has run smack up against a brick wall.
I'd be really grateful for some help.
Thank you.