I have a Crystal XI report that list all clients for a specified outpatient (recurring episode) program, last appointment, who they saw, and how many days since they were last seen. I couldnt get it to group properly to get the dadt the way I wanted it. It was suggested that I use an SQL Command. I am pulling data from an Intersystems Cache 5.0 database. I have never realy worked with SQL commands in crystal after some research this is what I came up with:
select
EP.patid
, EP.v_patient_name
, EP.episode_number
, EP.date_of_discharge
, EP.preadmit_admission_date
, EP.program_value
, APPQUERY.AppointmentStart
, APPQUERY.service_code
, APPQUERY.staffid
, APPQUERY.staff_name
, APPQUERY.site_name
, APPQUERY.MaxAppt
from episode_history EP
left outer join
( select
APP.PATID
, APP.episode_number
, cast(string(cast(APP.appointment_date as varchar), ' ', cast(convert(time, APP.appointment_start_time) as varchar)) as datetime) as "AppointmentStart"
, APP.service_code
, APP.staffID
, APP.staff_name
, APP.site_name
, MAXAPP.MaxAppt
from
appt_data APP
inner join
(select
patid
, episode_number
, max(cast(string(cast(appointment_date as varchar), ' ', cast(convert(time, appointment_start_time) as varchar)) as datetime)) as "MaxAppt"
from appt_data
where program_code = '{?Program}'
group by patid, episode_number) as MAXAPP on
((APP.patid = MAXAPP.patid) and (APP.episode_number = MAXAPP.episode_number) and (cast(string(cast(APP.appointment_date as varchar), ' ', cast(convert(time, APP.appointment_start_time) as varchar)) as datetime) = MAXAPP.MaxAppt))
) as APPQUERY on ((EP.patid = APPQUERY.patid) and (EP.episode_number = APPQUERY.episode_number))
where
EP.program_code = '{?Program}' and
EP.date_of_discharge is null
When I try to run it I am getting several errors:
1) Failed to retrieve data from database
2)
Im sure my syntax is all messed up can anyone shed some light as to what I may be doing wrong.
Thanks
select
EP.patid
, EP.v_patient_name
, EP.episode_number
, EP.date_of_discharge
, EP.preadmit_admission_date
, EP.program_value
, APPQUERY.AppointmentStart
, APPQUERY.service_code
, APPQUERY.staffid
, APPQUERY.staff_name
, APPQUERY.site_name
, APPQUERY.MaxAppt
from episode_history EP
left outer join
( select
APP.PATID
, APP.episode_number
, cast(string(cast(APP.appointment_date as varchar), ' ', cast(convert(time, APP.appointment_start_time) as varchar)) as datetime) as "AppointmentStart"
, APP.service_code
, APP.staffID
, APP.staff_name
, APP.site_name
, MAXAPP.MaxAppt
from
appt_data APP
inner join
(select
patid
, episode_number
, max(cast(string(cast(appointment_date as varchar), ' ', cast(convert(time, appointment_start_time) as varchar)) as datetime)) as "MaxAppt"
from appt_data
where program_code = '{?Program}'
group by patid, episode_number) as MAXAPP on
((APP.patid = MAXAPP.patid) and (APP.episode_number = MAXAPP.episode_number) and (cast(string(cast(APP.appointment_date as varchar), ' ', cast(convert(time, APP.appointment_start_time) as varchar)) as datetime) = MAXAPP.MaxAppt))
) as APPQUERY on ((EP.patid = APPQUERY.patid) and (EP.episode_number = APPQUERY.episode_number))
where
EP.program_code = '{?Program}' and
EP.date_of_discharge is null
When I try to run it I am getting several errors:
1) Failed to retrieve data from database
2)
Im sure my syntax is all messed up can anyone shed some light as to what I may be doing wrong.
Thanks