Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
3rookerbar
Starting Member
8 Posts |
Posted - 2007-07-11 : 15:19:57
|
| I am trying to exclude patients from a dataset. There are multiple records per patid in this dataset. I have the following code:SELECT meds.PATID, meds.MEDICATION, meds.MEDTYPEFROM meds INNER JOIN patient ON meds.PATID = patient.PATIDWHERE (((meds.MEDTYPE) Not In ("FI (Fusion Inhibitor)","NNUC (","Non-nucleoside","NRTI & NNUC","NRTI (Nucleoside/tide Rev","PI (Protease Inhibitor)")));I want to exclude all patient records if the patient had any of the above exclusions ever. If they have the exclusion if one record get rid of the rest of the records for that patient. Right now the code only excludes the particular record. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-07-11 : 15:26:28
|
| [code]SELECT meds.PATID, meds.MEDICATION, meds.MEDTYPEFROM medsINNER JOIN patient ON patient.PATID = meds.PATIDLEFT JOIN ( SELECT PATID FROM meds WHERE MEDTYPE IN ('FI (Fusion Inhibitor)', 'NNUC (','Non-nucleoside', 'NRTI & NNUC', 'NRTI (Nucleoside/tide Rev', 'PI (Protease Inhibitor)') ) AS d ON d.PatID = meds.PatidWHERE d.PatID IS NULL[/code]Peter LarssonHelsingborg, Sweden |
 |
|
|
3rookerbar
Starting Member
8 Posts |
Posted - 2007-07-11 : 15:41:54
|
| I just realized my code is more simple than I orgianally posted. SELECT meds.PATID, meds.MEDICATION, meds.MEDTYPEFROM medsWHERE (((meds.MEDTYPE) Not In ("FI (Fusion Inhibitor)","NNUC (","Non-nucleoside","NRTI & NNUC","NRTI (Nucleoside/tide Rev","PI (Protease Inhibitor)"))); |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-07-11 : 15:47:25
|
Hey! This is a great way to increase my post count  SELECT meds.PATID, meds.MEDICATION, meds.MEDTYPEFROM medsLEFT JOIN ( SELECT PATID FROM meds WHERE MEDTYPE IN ('FI (Fusion Inhibitor)', 'NNUC (','Non-nucleoside', 'NRTI & NNUC', 'NRTI (Nucleoside/tide Rev', 'PI (Protease Inhibitor)') ) AS d ON d.PatID = meds.PatidWHERE d.PatID IS NULLPeter LarssonHelsingborg, Sweden |
 |
|
|
3rookerbar
Starting Member
8 Posts |
Posted - 2007-07-11 : 16:05:59
|
| That worked great except MS Access was rewriting your code when I pasted in the SQL view. I had to change back to what you gave me. You gotta love Access. Thanks. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
3rookerbar
Starting Member
8 Posts |
Posted - 2007-07-11 : 21:29:58
|
If Peter would have answered any faster my head would have spun off my shoulders. But thanks for the advice anyways............ |
 |
|
|
|
|
|
|
|