scottaherbst
Technical User
I'm working with CR10 on a SQL server DB.
I'm working with patient records and I want to bring up the most recent diagnosis for each different service they receive. I wrote the command line:
Select episode_history.patid, episode_history.episode_number, episode_history.program_X_type_code, episode_history.program_X_type_value, history_diagnosis.date_of_diagnosis, history_diagnosis.axis_i_diag_value_1, history_diagnosis.axis_ii_diag_value_1, history_diagnosis.axis_III_diag_value_1, history_diagnosis.axis_IV_prim_sup_grp_code, history_diagnosis.axis_IV_soc_env_code, history_diagnosis.axis_IV_educ_code, history_diagnosis.axis_IV_occ_code, history_diagnosis.axis_IV_housing_code, history_diagnosis.axis_IV_housing_value, history_diagnosis.axis_IV_eco_value, history_diagnosis.axis_IV_health_serv_value, history_diagnosis.axis_IV_legsys_value, history_diagnosis.axis_IV_other_prob_value, history_diagnosis.diagnosis_type_value, history_diagnosis.diagnosis_type_code, history_diagnosis.axis_v_gaf_code FROM SYSTEM.episode_history episode_history LEFT OUTER JOIN SYSTEM.history_diagnosis history_diagnosis ON episode_history.PATID = history_diagnosis.PATID AND episode_history.episode_number = history_diagnosis.episode_number WHERE history_diagnosis.date_of_diagnosis = (SELECT MAX(history_diagnosis.date_of_diagnosis) FROM SYSTEM.history_diagnosis A, episode_history B WHERE a.patid = b.patid AND a.episode_number = b.episode_number)
And after a few minutes got a general server error. Then I tried a version of the same thing but changed the A's and the B's specifying tables back to the original table names. So now it looks like this:
Select episode_history.patid, episode_history.episode_number, episode_history.program_X_type_code, episode_history.program_X_type_value, history_diagnosis.date_of_diagnosis, history_diagnosis.axis_i_diag_value_1, history_diagnosis.axis_ii_diag_value_1, history_diagnosis.axis_III_diag_value_1, history_diagnosis.axis_IV_prim_sup_grp_code, history_diagnosis.axis_IV_soc_env_code, history_diagnosis.axis_IV_educ_code, history_diagnosis.axis_IV_occ_code, history_diagnosis.axis_IV_housing_code, history_diagnosis.axis_IV_housing_value, history_diagnosis.axis_IV_eco_value, history_diagnosis.axis_IV_health_serv_value, history_diagnosis.axis_IV_legsys_value, history_diagnosis.axis_IV_other_prob_value, history_diagnosis.diagnosis_type_value, history_diagnosis.diagnosis_type_code, history_diagnosis.axis_v_gaf_code FROM SYSTEM.episode_history episode_history LEFT OUTER JOIN SYSTEM.history_diagnosis history_diagnosis ON episode_history.PATID = history_diagnosis.PATID AND episode_history.episode_number = history_diagnosis.episode_number WHERE history_diagnosis.date_of_diagnosis = (SELECT MAX(history_diagnosis.date_of_diagnosis) FROM SYSTEM.history_diagnosis, episode_history WHERE history_diagnosis.patid = episode_history.patid AND history_diagnosis.episode_number = episode_history.episode_number)
Now, I'm not getting anything. I let it run for almost 2 hours and it never finished. I stopped it and ran it over and now its been going for about 1/2 hour. To provide some context, our DB is really slow and clunky, so its not irregular for a report such as this to take 10-15 minutes to run (depending on the time of day and traffic), but its extremely unusual that it take this long, so I'm thinking there is something wrong with my command. Any ideas?
I'm working with patient records and I want to bring up the most recent diagnosis for each different service they receive. I wrote the command line:
Select episode_history.patid, episode_history.episode_number, episode_history.program_X_type_code, episode_history.program_X_type_value, history_diagnosis.date_of_diagnosis, history_diagnosis.axis_i_diag_value_1, history_diagnosis.axis_ii_diag_value_1, history_diagnosis.axis_III_diag_value_1, history_diagnosis.axis_IV_prim_sup_grp_code, history_diagnosis.axis_IV_soc_env_code, history_diagnosis.axis_IV_educ_code, history_diagnosis.axis_IV_occ_code, history_diagnosis.axis_IV_housing_code, history_diagnosis.axis_IV_housing_value, history_diagnosis.axis_IV_eco_value, history_diagnosis.axis_IV_health_serv_value, history_diagnosis.axis_IV_legsys_value, history_diagnosis.axis_IV_other_prob_value, history_diagnosis.diagnosis_type_value, history_diagnosis.diagnosis_type_code, history_diagnosis.axis_v_gaf_code FROM SYSTEM.episode_history episode_history LEFT OUTER JOIN SYSTEM.history_diagnosis history_diagnosis ON episode_history.PATID = history_diagnosis.PATID AND episode_history.episode_number = history_diagnosis.episode_number WHERE history_diagnosis.date_of_diagnosis = (SELECT MAX(history_diagnosis.date_of_diagnosis) FROM SYSTEM.history_diagnosis A, episode_history B WHERE a.patid = b.patid AND a.episode_number = b.episode_number)
And after a few minutes got a general server error. Then I tried a version of the same thing but changed the A's and the B's specifying tables back to the original table names. So now it looks like this:
Select episode_history.patid, episode_history.episode_number, episode_history.program_X_type_code, episode_history.program_X_type_value, history_diagnosis.date_of_diagnosis, history_diagnosis.axis_i_diag_value_1, history_diagnosis.axis_ii_diag_value_1, history_diagnosis.axis_III_diag_value_1, history_diagnosis.axis_IV_prim_sup_grp_code, history_diagnosis.axis_IV_soc_env_code, history_diagnosis.axis_IV_educ_code, history_diagnosis.axis_IV_occ_code, history_diagnosis.axis_IV_housing_code, history_diagnosis.axis_IV_housing_value, history_diagnosis.axis_IV_eco_value, history_diagnosis.axis_IV_health_serv_value, history_diagnosis.axis_IV_legsys_value, history_diagnosis.axis_IV_other_prob_value, history_diagnosis.diagnosis_type_value, history_diagnosis.diagnosis_type_code, history_diagnosis.axis_v_gaf_code FROM SYSTEM.episode_history episode_history LEFT OUTER JOIN SYSTEM.history_diagnosis history_diagnosis ON episode_history.PATID = history_diagnosis.PATID AND episode_history.episode_number = history_diagnosis.episode_number WHERE history_diagnosis.date_of_diagnosis = (SELECT MAX(history_diagnosis.date_of_diagnosis) FROM SYSTEM.history_diagnosis, episode_history WHERE history_diagnosis.patid = episode_history.patid AND history_diagnosis.episode_number = episode_history.episode_number)
Now, I'm not getting anything. I let it run for almost 2 hours and it never finished. I stopped it and ran it over and now its been going for about 1/2 hour. To provide some context, our DB is really slow and clunky, so its not irregular for a report such as this to take 10-15 minutes to run (depending on the time of day and traffic), but its extremely unusual that it take this long, so I'm thinking there is something wrong with my command. Any ideas?