How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask ATLPROG Your Own Question

ATLPROG
ATLPROG, Computer Software Engineer
Category: Programming
Satisfied Customers: 7677
Experience:  MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
44910485
Type Your Programming Question Here...
ATLPROG is online now
A new question is answered every 9 seconds

Need sql query to pull from the same column of a table under

Customer Question

Need sql query to pull from the same column of a table under different conditions. Have two tables. Need to pull all data from first table and only one column from the second table multiple times under different conditions.
Submitted: 10 months ago.
Category: Programming
Expert:  Ingo U replied 10 months ago.

Hi,

can you upload information on the schema of the tables involved? For example, if you had SQL server generate CREATE scripts for the tables and upload them for me, I could replicate your situation at my end. Or, just backup your whole database if it's not too large/complex/confidential and upload the whole thing.

Some simple example of source and destination table contents before and after the operation would be helpful, too.

Thanks,

Ingo U

Customer: replied 10 months ago.
Here is my query so farselect
ENT.PATIENT.PAT_SEQ,
ENT.PATIENT.CREATED_DT,
ent.patient.created_tz,
ent.patient.created_by_seq,
ENT.PATIENT.MODIFIED_DT,
ent.patient.modified_tz,
ent.patient.modified_by_seq,
ent.patient.record_version,
ent.patient.enterprise_seq,
ent.patient.cpi_seq,
ent.patient.organization_seq,
ent.patient.previous_organization_seq,
ent.patient.episode_of_care_seq,
ent.patient.patient_type_seq,
ent.patient.patient_visit_type_seq,
ent.patient.bed_seq,
ent.patient.previous_bed_seq,
ent.patient.arrival_mode_seq,
ent.patient.departure_mode_seq,
ent.patient.name_prefix,
ent.patient.name_prefix_lseq,
ent.patient.last_name,
ent.patient.middle_name,
ent.patient.first_name,
ent.patient.name_suffix,
ent.patient.name_suffix_lseq,
ent.patient.birth_dt_approximate_fl,
ent.patient.birth_dt,
ent.patient.birth_tz,
ent.patient.gender,
ent.patient.gender_lseq,
ent.patient.facility_id,
ent.patient.dept_id,
ent.patient.email_address,
ENT.PATIENT.PATIENT_ID,
ent.patient.visit_number,
ent.patient.medrec_id,
ent.patient.soc_sec_no,
ent.patient.barcode,
ent.patient.patient_status,
ent.patient.patient_status_lseq,
ent.patient.patient_status_detail,
ent.patient.patient_status_detail_lseq,
ent.patient.pat_type_group,
ent.patient.pat_type_group_lseq,
ent.patient.acuity_class,
ent.patient.acuity_class_lseq,
ent.patient.payor_class,
ent.patient.payor_class_seq,
ENT.PATIENT.ADMIT_DT,
ent.patient.admit_tz,
ent.patient.expected_admission_dt,
ent.patient.expected_admission_tz,
ent.patient.transfer_dt,
ent.patient.transfer_tz,
ENT.PATIENT.DISCHARGE_DT,
ent.patient.discharge_tz,
ent.patient.text_1,
ent.patient.text_2,
ent.patient.room_id,
ent.patient.bed_id,
ent.patient.source_system,
ent.patient.source_system_seq,
ent.patient.accommodation_code,
ent.patient.accommodation_seq,
ent.patient.service,
ent.patient.complaint,
ent.patient.complaint_onset_dt,
ent.patient.complaint_onset_tz,
ent.patient.admit_source,
ent.patient.admit_source_lseq,
ent.patient.admit_type,
ent.patient.admit_type_lseq,
ent.patient.condition,
ent.patient.condition_lseq,
ent.patient.discharge_disposition,
ent.patient.discharge_disposition_seq,
ent.patient.discharge_condition,
ent.patient.discharge_condition_lseq,
ent.patient.disposition_decision_dt,
ent.patient.final_discharge_ind,
ent.patient.final_discharge_ind_lseq,
ent.patient.cancel_reason,
ent.patient.cancel_reason_lseq,
ent.patient.expired_fl,
ent.patient.expired_dt,
ent.patient.expired_tz,
ent.patient.purge_ind,
ent.patient.purge_ind_lseq,
ent.patient.purge_dt,
ent.patient.purge_tz,
ent.patient.last_result_dt,
ent.patient.last_result_tz,
ent.patient.financial_support,
ent.patient.financial_support_lseq,
ent.patient.publicity,
ent.patient.publicity_seq,
ent.patient.confidentiality_level,
ent.patient.confidentiality_level_seq,
ent.patient.visit_protection_fl,
ent.patient.visit_protection_dt,
ent.patient.visit_protection_tz,
ent.patient.cancel_admission_reason,
ent.patient.cancel_admission_dt,
ent.patient.cancel_admission_tz,
ent.patient.cancelled_by,
ent.patient.height,
ent.patient.height_unit,
ent.patient.height_unit_lseq,
ent.patient.weight,
ent.patient.weight_unit,
ent.patient.weight_unit_lseq,
ent.patient.recurring_treatment_end_dt,
ent.patient.recurring_treatment_end_tz,
ent.patient.lmp_date,
ent.patient.pregnant_fl,
ent.patient.information_given_by,
ent.patient.brought_in_by,
ent.patient.disposition_decision_tz,
ent.patient.corporate_billing_class_lseq,
ent.patient.patient_type_class_seq,
ent.patient.service_seq,
ent.patient.pr_dept_id,
b.staff_seq AS "Attend Staff Seq",
c.staff_seq AS "Admitting Staff Seq",
d.staff_seq AS "Primary Care Staff Seq",
e.staff_seq AS "Ordering Staff Seq",
f.staff_seq AS "Performing Staff Seq",
g.staff_seq AS "Referring Staff Seq"FROM
ENT.PATIENT inner join ent.staff_assign b
on ent.patient.pat_seq = b.pat_seq inner join
ent.staff_assign c
on ent.patient.pat_seq = c.pat_seq inner join
ent.staff_assign d
on ent.patient.pat_seq = d.pat_seq inner join
ent.staff_assign e
on ent.patient.pat_seq = e.pat_seq inner join
ent.staff_assign f
on ent.patient.pat_seq = f.pat_seq inner join
ent.staff_assign g
on ent.patient.pat_seq = g.pat_seq
where b.care_reln_code = 'ADMD' and
c.care_reln_code = 'ATMD' and
d.care_reln_code = 'PCMD' and
e.care_reln_code = 'ORD' and
f.care_reln_code = 'PER' and
g.care_reln_code = 'REF'
and ent.patient.pat_seq = '123456'
Customer: replied 10 months ago.
Here is the staff_assign tableent.staff_assign.staff_assign_seq,
ENT.STAFF_ASSIGN.CREATED_DT,
ent.staff_assign.created_tz,
ent.staff_assign.created_by_seq,
ent.staff_assign.modified_dt,
ent.staff_assign.modified_tz,
ent.staff_assign.modified_by_seq,
ent.staff_assign.record_version,
ent.staff_assign.enterprise_seq,
ENT.STAFF_ASSIGN.STAFF_SEQ,
ENT.STAFF_ASSIGN.PAT_SEQ,
ent.staff_assign.assign_by_staff_seq,
ent.staff_assign.cover_by_staff_seq,
ent.staff_assign.close_by_staff_seq,
ent.staff_assign.cover_by_group_seq,
ent.staff_assign.practice_group_seq,
ent.staff_assign.specialty_seq,
ent.staff_assign.care_reln_code,
ent.staff_assign.care_reln_seq,
ENT.STAFF_ASSIGN.START_DT,
ent.staff_assign.start_tz,
ent.staff_assign.start_utc,
ENT.STAFF_ASSIGN.END_DT,
ent.staff_assign.end_tz,
ent.staff_assign.end_utc,
ent.staff_assign.close_by_reason,
ent.staff_assign.source_system,
ent.staff_assign.source_system_seq,
ent.staff_assign.pat_finder_fl
Customer: replied 10 months ago.
My query pulls 0 results right now. I can eliminate all the care_reln_codes but ATMD and PCMD and get data, but there are two rows for that due to the pat_seq being in the staff_assign table twice for when the ATMD changed. I need it all on one row with only the most recent modified_dt for each care_reln_code and I need the data to pull even if there is no data for all the care_reln_codes.
Expert:  Ingo U replied 10 months ago.

I'm sorry,
After reviewing the question, I regret that I won't be able to assist you at this time.

I am opting out and opening the question up to other professionals here who may be able to help.

Regards,
Ingo U