From: | Norm Garand <indianlakesolutions(at)rogers(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | A better look at trying to insert a Conditional in a SELECT statement |
Date: | 2007-07-18 05:33:00 |
Message-ID: | 326614.81076.qm@web88315.mail.re4.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hi Again:
thanks to those who sent me responses on my first post. I'll try to explain a bit better. There
are several parameters that are passed by the user. Each of the parameters that are being passed,
may have a NULL value, or an actual numerical value. The parameters filter a large report down a
to small amount of records. With that being said, the problem I'm encountering is that I can't
seem to insert a conditional (whether it be a CASE statement or an IF statement) in the middle of
the SELECT statement. I'm not sure if the problem stems from using the ROWTYPE variable notation.
Here is the complete code. It works as long as a NULL value doesn't get passed.
To show what I mean, I'd like to insert the conditional around this line (23rd from the bottom):
f.id = pid.specific_location_cid AND f.long_desc = $7
-- Function: sp_hirs_a_01dd(integer, character varying, integer, character varying, character
varying, character varying, character varying)
-- DROP FUNCTION sp_hirs_a_01dd(integer, character varying, integer, character varying, character
varying, character varying, character varying);
CREATE OR REPLACE FUNCTION sp_hirs_a_01dd(integer, character varying, integer, character varying,
character varying, character varying, character varying)
RETURNS SETOF rec_dd_holder AS
$BODY$
DECLARE
r rec_dd_holder%rowtype;
BEGIN
FOR r IN
SELECT DISTINCT(pi.serial_number) AS "Incident ID",
to_char(pi.incident_date,'Mon-dd-yyyy') AS "Incident date",
to_char(pi.date_created,'Mon-dd-yyyy') AS "Report Date",
CASE
WHEN EXTRACT ( MONTH FROM pi.incident_date ) = 1 THEN 1
WHEN EXTRACT ( MONTH FROM pi.incident_date ) = 2 THEN 1
WHEN EXTRACT ( MONTH FROM pi.incident_date ) = 3 THEN 1
WHEN EXTRACT ( MONTH FROM pi.incident_date ) = 4 THEN 2
WHEN EXTRACT ( MONTH FROM pi.incident_date ) = 5 THEN 2
WHEN EXTRACT ( MONTH FROM pi.incident_date ) = 6 THEN 2
WHEN EXTRACT ( MONTH FROM pi.incident_date ) = 7 THEN 3
WHEN EXTRACT ( MONTH FROM pi.incident_date ) = 8 THEN 3
WHEN EXTRACT ( MONTH FROM pi.incident_date ) = 9 THEN 3
WHEN EXTRACT ( MONTH FROM pi.incident_date ) = 10 THEN 4
WHEN EXTRACT ( MONTH FROM pi.incident_date ) = 11 THEN 4
WHEN EXTRACT ( MONTH FROM pi.incident_date ) = 12 THEN 4
END AS "Quarter",
pf.name AS "Facility",
pl.name AS "General Location",
f.long_desc AS "Specific Location",
b.long_desc AS "Status",
pi.person_age AS "Age",
CASE
WHEN pi.gender_code_id ='31' THEN 'M'
WHEN pi.gender_code_id ='32' THEN 'F'
ELSE NULL
END
AS "Gender",
to_char(pi.incident_date,'hh24:mm') AS "Time",
pc.long_desc AS "Incident Type",
a.long_desc AS "Incident Subtype",
CASE WHEN pid.fallscf_behavoiur_val ='t' THEN 'Behaviour. ' WHEN pid.fallscf_behavoiur_val ='f'
THEN '' END ||
CASE WHEN pid.fallscf_bowel_bladder_val ='t' THEN 'Bowel/Bladder Problem.' WHEN
pid.fallscf_bowel_bladder_val ='f' THEN '' END ||
CASE WHEN pid.fallscf_comm_information_val ='t' THEN 'Communication/Information. ' WHEN
pid.fallscf_comm_information_val = 'f' THEN '' END ||
CASE WHEN pid.fallscf_env_condition_val ='t' THEN 'Environmental Conditions. ' WHEN
pid.fallscf_env_condition_val = 'f' THEN '' END ||
CASE WHEN pid.fallscf_eq_malfunction_val ='t' THEN 'Equipment Malfunction. ' WHEN
pid.fallscf_eq_malfunction_val = 'f' THEN '' END ||
CASE WHEN pid.fallscf_eq_supplies_val ='t' THEN 'Equipment/Supplies Unavailable. ' WHEN
pid.fallscf_eq_supplies_val = 'f' THEN '' END ||
CASE WHEN pid.fallscf_visitor_val ='t' THEN 'Family/Visitor Assisting. ' WHEN
pid.fallscf_visitor_val = 'f' THEN '' END ||
CASE WHEN pid.fallscf_footwear_val ='t' THEN 'Inappropriate Footwear. ' WHEN
pid.fallscf_footwear_val = 'f' THEN '' END ||
CASE WHEN pid.fallscf_instructionsnotfollowed_val ='t' THEN 'Instructions Not Followed. ' WHEN
pid.fallscf_instructionsnotfollowed_val = 'f' THEN '' END ||
CASE WHEN pid.fallscf_interference_val ='t' THEN 'Interference/Interruption. ' WHEN
pid.fallscf_interference_val = 'f' THEN '' END ||
CASE WHEN pid.fallscf_material_val ='t' THEN 'Material/Liquid on Floor. ' WHEN
pid.fallscf_material_val = 'f' THEN '' END ||
CASE WHEN pid.fallscf_medication_val ='t' THEN 'Medication. ' WHEN pid.fallscf_medication_val =
'f' THEN '' END ||
CASE WHEN pid.fallscf_overreaching_val ='t' THEN 'Overreaching. ' WHEN
pid.fallscf_overreaching_val = 'f' THEN '' END ||
CASE WHEN pid.fallscf_physical_cond_val ='t' THEN 'Physical/Medical Condition. ' WHEN
pid.fallscf_physical_cond_val = 'f' THEN '' END ||
CASE WHEN pid.fallscf_policy_val ='t' THEN 'Policy/Procedure. ' WHEN pid.fallscf_policy_val =
'f' THEN '' END ||
CASE WHEN pid.fallscf_substance_val ='t' THEN 'Suspected Substance/Alcohol Use. ' WHEN
pid.fallscf_substance_val = 'f' THEN '' END ||
CASE WHEN pid.fallscf_unexpectmovement_val ='t' THEN 'Unexpected Movement. ' WHEN
pid.fallscf_unexpectmovement_val = 'f' THEN '' END ||
CASE WHEN pid.fallscf_other_val ='t' THEN 'Other' WHEN pid.fallscf_other_val = 'f' THEN '' END
||
CASE WHEN pid.vartreatcf_body_mechanics_val ='t' THEN 'Body Mechanics. ' WHEN
pid.vartreatcf_body_mechanics_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_calculation_val ='t' THEN 'Calculation. ' WHEN
pid.vartreatcf_calculation_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_chart_doc_val ='t' THEN 'Chart Documentation. ' WHEN
pid.vartreatcf_chart_doc_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_communication_val ='t' THEN 'Communication/Information. ' WHEN
pid.vartreatcf_communication_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_computer_probl_val ='t' THEN 'Computer Problems. ' WHEN
pid.vartreatcf_computer_probl_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_dispensing_admi_val ='t' THEN 'Dispensing/Administration. ' WHEN
pid.vartreatcf_dispensing_admi_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_env_conditions_val ='t' THEN 'Environmental Conditions. ' WHEN
pid.vartreatcf_env_conditions_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_eq_supplies_val ='t' THEN 'Equipment/Supplies. ' WHEN
pid.vartreatcf_eq_supplies_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_instr_notfollowed_val ='t' THEN 'Instructions Not Followed. ' WHEN
pid.vartreatcf_instr_notfollowed_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_interference_val ='t' THEN 'Interference/Interruption. ' WHEN
pid.vartreatcf_interference_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_labelling_val ='t' THEN 'Labeling. ' WHEN pid.vartreatcf_labelling_val
= 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_medic_notlocked_val ='t' THEN 'Medication Not Locked. ' WHEN
pid.vartreatcf_medic_notlocked_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_medic_packaging_val ='t' THEN 'Medication Packaging. ' WHEN
pid.vartreatcf_medic_packaging_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_namesound_lookalike_val ='t' THEN 'Name Sound/Look Alike. ' WHEN
pid.vartreatcf_namesound_lookalike_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_order_requisition_val ='t' THEN 'Order/Requisition. ' WHEN
pid.vartreatcf_order_requisition_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_patient_ident_missing_val ='t' THEN 'Patient Identification Missing. '
WHEN pid.vartreatcf_patient_ident_missing_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_patient_registration_error_val ='t' THEN 'Patient Registration Error.
' WHEN pid.vartreatcf_patient_registration_error_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_policy_val ='t' THEN 'Policy/Procedure. ' WHEN
pid.vartreatcf_policy_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_prep_fortest_val ='t' THEN 'Preparation for test. ' WHEN
pid.vartreatcf_prep_fortest_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_selfmedicating_val ='t' THEN 'Self-Medicating. ' WHEN
pid.vartreatcf_selfmedicating_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_transcription_val ='t' THEN 'Transcription. ' WHEN
pid.vartreatcf_transcription_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_transport_val ='t' THEN 'Transport/Delivery. ' WHEN
pid.vartreatcf_transport_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_unexp_movement_val ='t' THEN 'Unexpected Movement. ' WHEN
pid.vartreatcf_unexp_movement_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_wrong_patient_val ='t' THEN 'Wrong Patient. ' WHEN
pid.vartreatcf_wrong_patient_val = 'f' THEN '' END ||
CASE WHEN pid.vartreatcf_other_val ='t' THEN 'Other' WHEN pid.vartreatcf_other_val = 'f' THEN
'' END ||
CASE WHEN pid.misccomplcf_behaviour_val ='t' THEN 'Behaviour. ' WHEN
pid.misccomplcf_behaviour_val = 'f' THEN '' END ||
CASE WHEN pid.misccomplcf_body_mechanics_val ='t' THEN 'Body Mechanics. ' WHEN
pid.misccomplcf_body_mechanics_val = 'f' THEN '' END ||
CASE WHEN pid.misccomplcf_communication_val ='t' THEN 'Communication/Information. ' WHEN
pid.misccomplcf_communication_val = 'f' THEN '' END ||
CASE WHEN pid.misccomplcf_computer_probl_val ='t' THEN 'Computer Problems. ' WHEN
pid.misccomplcf_computer_probl_val = 'f' THEN '' END ||
CASE WHEN pid.misccomplcf_env_conditions_val ='t' THEN 'Environmental Conditions. ' WHEN
pid.misccomplcf_env_conditions_val = 'f' THEN '' END ||
CASE WHEN pid.misccomplcf_eq_malfunction_val ='t' THEN 'Equipment Malfunction. ' WHEN
pid.misccomplcf_eq_malfunction_val = 'f' THEN '' END ||
CASE WHEN pid.misccomplcf_eq_supplies_val ='t' THEN 'Equipment/Supplies Unavailable. ' WHEN
pid.misccomplcf_eq_supplies_val = 'f' THEN '' END ||
CASE WHEN pid.misccomplcf_expectations_val ='t' THEN 'Expectations. ' WHEN
pid.misccomplcf_expectations_val = 'f' THEN '' END ||
CASE WHEN pid.misccomplcf_instructions_val ='t' THEN 'Instructions Not Followed. ' WHEN
pid.misccomplcf_instructions_val = 'f' THEN '' END ||
CASE WHEN pid.misccomplcf_interference_val ='t' THEN 'Interference/Interruption. ' WHEN
pid.misccomplcf_interference_val = 'f' THEN '' END ||
CASE WHEN pid.misccomplcf_physical_condition_val ='t' THEN 'Physical/Medical Condition. ' WHEN
pid.misccomplcf_physical_condition_val = 'f' THEN '' END ||
CASE WHEN pid.misccomplcf_policy_val ='t' THEN 'Policy/Procedure. ' WHEN
pid.misccomplcf_policy_val = 'f' THEN '' END ||
CASE WHEN pid.misccomplcf_susp_substance_val ='t' THEN 'Suspected Substance/Alcohol Use. ' WHEN
pid.misccomplcf_susp_substance_val = 'f' THEN '' END ||
CASE WHEN pid.misccomplcf_unexp_movement_val ='t' THEN 'Unexpected Movement. ' WHEN
pid.misccomplcf_unexp_movement_val = 'f' THEN '' END ||
CASE WHEN pid.misccomplcf_other_val ='t' THEN 'Other' WHEN pid.misccomplcf_other_val = 'f' THEN
'' END
AS "Cont Factors",
CASE
WHEN pid.bed_alarms_val = 'On' THEN 'On'
WHEN pid.bed_alarms_val = 'Off' THEN 'Off'
ELSE NULL
END
AS "Bed Alarms",
CASE
WHEN pid.height_bedstretcher_val = 'Up' THEN 'Up'
WHEN pid.height_bedstretcher_val = 'Down' THEN 'Down'
ELSE NULL
END
AS "Bed/Stretcher",
CASE
WHEN pid.brakes_val = 'On' THEN 'On'
WHEN pid.brakes_val = 'Off' THEN 'Off'
ELSE NULL
END
AS "Brakes",
CASE
WHEN pid.restraints_val ='On' THEN 'On'
WHEN pid.restraints_val ='Off' THEN 'Off'
ELSE NULL
END
AS "Restraints",
CASE
WHEN pid.siderails_val ='Up and Down' THEN 'Up and Down'
WHEN pid.siderails_val ='Up' THEN 'Up'
WHEN pid.siderails_val ='Down' THEN 'Down'
ELSE NULL
END
AS "Siderails",
CASE
WHEN pid.walking_aid_val ='Yes' THEN 'Yes'
WHEN pid.walking_aid_val ='No' THEN 'No'
ELSE NULL
END
AS "Walking Aid",
CASE
WHEN pi.incident_witnessed ='t' THEN 'Yes'
ELSE NULL
END
AS "Witnessed",
CASE
WHEN high_risk_medication_val ='t' THEN 'Yes'
ELSE NULL
END
AS "High Risk Medictation",
CASE WHEN pid.inc_nature_abrasion_val ='t' THEN 'Abrasion/Bruise/Contusion. ' WHEN
pid.inc_nature_abrasion_val = 'f' THEN '' END ||
CASE WHEN pid.inc_nature_allergic_reaction_val ='t' THEN 'Allergic Reaction. ' WHEN
pid.inc_nature_allergic_reaction_val = 'f' THEN '' END ||
CASE WHEN pid.inc_nature_back_injury_val ='t' THEN 'Back Injury. ' WHEN
pid.inc_nature_back_injury_val = 'f' THEN '' END ||
CASE WHEN pid.inc_nature_bite_val ='t' THEN 'Bite. ' WHEN pid.inc_nature_bite_val = 'f' THEN ''
END ||
CASE WHEN pid.inc_nature_bleeding_val ='t' THEN 'Bleeding/Hemorrhage. ' WHEN
pid.inc_nature_bleeding_val = 'f' THEN '' END ||
CASE WHEN pid.inc_nature_burn_val ='t' THEN 'Burn. ' WHEN pid.inc_nature_burn_val = 'f' THEN ''
END ||
CASE WHEN pid.inc_nature_dislocation_val ='t' THEN 'Displ. ' WHEN pid.inc_nature_dislocation_val
= 'f' THEN '' END ||
CASE WHEN pid.inc_nature_eyeinjury_val ='t' THEN 'Eye Injury/Splash. ' WHEN
pid.inc_nature_eyeinjury_val = 'f' THEN '' END ||
CASE WHEN pid.inc_nature_fracture_val ='t' THEN 'Fracture/Possible Fracture. ' WHEN
pid.inc_nature_fracture_val = 'f' THEN '' END ||
CASE WHEN pid.inc_nature_inhalation_val ='t' THEN 'Inhalation Exposure. ' WHEN
pid.inc_nature_inhalation_val = 'f' THEN '' END ||
CASE WHEN pid.inc_nature_laceration_val ='t' THEN 'Laceration/Cut. ' WHEN
pid.inc_nature_laceration_val = 'f' THEN '' END ||
CASE WHEN pid.inc_nature_loss_limb_val ='t' THEN 'Loss of Limb/Appendage. ' WHEN
pid.inc_nature_loss_limb_val = 'f' THEN '' END ||
CASE WHEN pid.inc_nature_effect_ofmedication_val ='t' THEN 'Outward Effect of Medication. ' WHEN
pid.inc_nature_effect_ofmedication_val = 'f' THEN '' END ||
CASE WHEN pid.inc_nature_puncture_val ='t' THEN 'Puncture. ' WHEN pid.inc_nature_puncture_val =
'f' THEN '' END ||
CASE WHEN pid.inc_nature_rash_val ='t' THEN 'Rash. ' WHEN pid.inc_nature_rash_val = 'f' THEN ''
END ||
CASE WHEN pid.inc_nature_skin_tear_val ='t' THEN 'Skin Tear. ' WHEN pid.inc_nature_skin_tear_val
= 'f' THEN '' END ||
CASE WHEN pid.inc_nature_sprain_val ='t' THEN 'Sprain/Strain. ' WHEN pid.inc_nature_sprain_val =
'f' THEN '' END ||
CASE WHEN pid.inc_nature_noneapparent_val ='t' THEN 'Not Apparent. ' WHEN
pid.inc_nature_noneapparent_val = 'f' THEN '' END ||
CASE WHEN pid.inc_nature_other_val ='t' THEN 'Other' WHEN pid.inc_nature_other_val = 'f' THEN ''
END
AS "Physical Nature",
d.long_desc AS "Degree of Injury",
e.long_desc AS "Mobility",
CASE
WHEN pid.diagnostic_ct_val ='t' THEN 'Yes'
ELSE NULL
END
AS "CT",
CASE
WHEN pid.diagnostic_labwork_val ='t' THEN 'Yes'
ELSE NULL
END
AS "Lab Work",
CASE
WHEN pid.diagnostic_mri_val ='t' THEN 'Yes'
ELSE NULL
END
AS "MRI",
CASE
WHEN pid.diagnostic_ultrasound_val ='t' THEN 'Yes'
ELSE NULL
END
AS "Ultrasound",
CASE
WHEN pid.diagnostic_xray_val ='t' THEN 'Yes'
ELSE NULL
END
AS "X-Ray",
CASE
WHEN pid.diagnostic_other_text != '' THEN pid.diagnostic_other_text
ELSE NULL
END
AS "Other",
CASE
WHEN pid.no_diagnostic_req_val ='t' THEN 'Yes'
ELSE NULL
END
AS "No Diagnostic Reqd",
CASE
WHEN pid.doc_chart_val ='t' THEN 'Yes'
ELSE NULL
END
AS "Chart Doc",
CASE
WHEN pid.doc_doctor_val ='t' THEN 'Yes'
ELSE NULL
END
AS "Doctor",
CASE
WHEN pid.doc_substitute_val ='t' THEN 'Yes'
ELSE NULL
END
AS "Sub Dec Maker",
CASE
WHEN pid.doc_supervisor_val ='t' THEN 'Yes'
ELSE NULL
END
AS "Supervisor",
CASE
WHEN pid.doc_maintenance_val ='t' THEN 'Yes'
ELSE NULL
END
AS "Maintenance",
CASE
WHEN pid.doc_safety_val ='t' THEN 'Yes'
ELSE NULL
END
AS "Safety",
CASE
WHEN pid.doc_pharmacy_val ='t' THEN 'Yes'
ELSE NULL
END
AS "Pharmacy",
CASE
WHEN pid.doc_police_val ='t' THEN 'Yes'
ELSE NULL
END
AS "Police",
CASE
WHEN pid.doc_security_val ='t' THEN 'Yes'
ELSE NULL
END
AS "Security",
CASE
WHEN pid.doc_compensation_val ='t' THEN 'Yes'
ELSE NULL
END
AS "Work Comp"
FROM incident pi, location pl, code pc, incident_detail pid, facility pf, code a, code b, code
d, code e, code f, code g, code h, code i, code j
WHERE ( pid.incident_type_cid = pc.id)
AND extract ( MONTH FROM pi.incident_date ) = $1
AND ( pi.person_status_code_id = g.id AND g.long_desc = $2 )
AND SUBSTRING(pi.serial_and_hospital_number FROM 9 FOR 5) = $3
AND ( pi.severity_code_id = j.id AND j.long_desc = $4 )
AND ( pid.incident_type_cid = h.id AND h.long_desc = $5 )
AND ( ( pid.inc_nature_abrasion_val = 't' AND pid.inc_nature_abrasion_cid = i.id
OR pid.inc_nature_allergic_reaction_val = 't' AND pid.inc_nature_allergic_reaction_cid = i.id
OR pid.inc_nature_back_injury_val = 't' AND pid.inc_nature_back_injury_cid = i.id
OR pid.inc_nature_bite_val = 't' AND pid.inc_nature_bite_cid = i.id
OR pid.inc_nature_bleeding_val = 't' AND pid.inc_nature_bleeding_cid = i.id
OR pid.inc_nature_burn_val = 't' AND pid.inc_nature_burn_cid = i.id
OR pid.inc_nature_dislocation_val = 't' AND pid.inc_nature_dislocation_cid = i.id
OR pid.inc_nature_eyeinjury_val = 't' AND pid.inc_nature_eyeinjury_cid = i.id
OR pid.inc_nature_fracture_val = 't' AND pid.inc_nature_fracture_cid = i.id
OR pid.inc_nature_inhalation_val = 't' AND pid.inc_nature_inhalation_cid = i.id
OR pid.inc_nature_laceration_val = 't' AND pid.inc_nature_laceration_cid = i.id
OR pid.inc_nature_loss_limb_val = 't' AND pid.inc_nature_loss_limb_cid = i.id
OR pid.inc_nature_effect_ofmedication_val = 't' AND pid.inc_nature_effect_ofmedication_cid =
i.id
OR pid.inc_nature_puncture_val = 't' AND pid.inc_nature_puncture_cid = i.id
OR pid.inc_nature_rash_val = 't' AND pid.inc_nature_rash_cid = i.id
OR pid.inc_nature_skin_tear_val = 't' AND pid.inc_nature_skin_tear_cid = i.id
OR pid.inc_nature_sprain_val = 't' AND pid.inc_nature_sprain_cid = i.id
OR pid.inc_nature_noneapparent_val = 't' AND pid.inc_nature_noneapparent_cid = i.id
OR pid.inc_nature_other_val = 't' AND pid.inc_nature_other_cid = i.id ) AND i.long_desc = $6 )
AND pi.id = pid.id
AND ( pid.incident_type_cid BETWEEN 117 AND 123 )
/**************************/
$7 IS NOT NULL THEN f.id = pid.specific_location_cid AND f.long_desc = $7
/**************************/
AND ( pi.location_id = pl.id )
AND pf.id = pl.facility_id
AND pi.person_status_code_id = b.id
AND ( ((a.id = pid.falls_subtype_cid) AND (pid.falls_subtype_cid BETWEEN 138 and 149))
OR ((a.id = pid.falls_subtype_cid) AND (pid.falls_subtype_cid BETWEEN 278 and 283))
OR ((a.id = pid.falls_subtype_cid) AND (pid.falls_subtype_cid = 285))
OR ((a.id = pid.medvariance_treatment_subtype_cid) AND (pid.medvariance_treatment_subtype_cid
BETWEEN 150 and 188))
OR ((a.id = pid.medvariance_treatment_subtype_cid) AND (pid.medvariance_treatment_subtype_cid =
284))
OR ((a.id = pid.misc_complaints_subtype_cid) AND (pid.misc_complaints_subtype_cid BETWEEN 189
and 224))
)
AND ( (d.id = pid.injury_degree_cid) AND (pid.injury_degree_cid BETWEEN 84 and 90))
AND ( (e.id = pid.mobility_level_cid) AND (pid.mobility_level_cid IN (258, 259, 260, 320)) )
AND pi.person_status_code_id IN (16,18,20,22,24,25,26,27)
ORDER BY pi.serial_number
loop
return NEXT r;
END loop;
return;
END
$BODY$
LANGUAGE 'plpgsql' STABLE STRICT;
ALTER FUNCTION sp_hirs_a_01dd(integer, character varying, integer, character varying, character
varying, character varying, character varying) OWNER TO postgres;
From | Date | Subject | |
---|---|---|---|
Next Message | Jyoti Seth | 2007-07-18 07:14:25 | Database Synchronization |
Previous Message | Jaime Casanova | 2007-07-18 04:50:00 | Re: Inserting an IF statement in the middle of a SELECT in pl/pgSQL code |