CR 10; SQL Server 2000
Tables - HR = Patiets; OT = Orders
Output desired - list of patients with primary order (rank=1) or patients with no orders
Database setup - HR left outer join OT
Record selection criteria - {hr.pat_stat} = 'Active' and {hr.pat_type} = 'Supplies Only' and (isnull({ot.rank}) or {ot.rank} = 1)
This creates the following SQL in crystal -
SELECT "HR"."LAST_NAME", "HR"."PAT_TYPE", "HR"."PAT_STAT", "OT"."RANK", "HR"."FIRST_NAME"
FROM "CPR_SQL"."dbo"."HR" "HR" LEFT OUTER JOIN "CPR_SQL"."dbo"."OT" "OT" ON "HR"."MRN"="OT"."MRN"
WHERE "HR"."PAT_STAT"='Active' AND "HR"."PAT_TYPE"='Supplies Only' AND ("OT"."RANK" IS NULL OR "OT"."RANK"=1)
Problem - the patients without any orders do not appear.
I copy this into Enterprise Manager and they appear with a rank = null.
Why are they not in my report?
In summary - how do I join two tables where I include all the records in the left table and the records in the right table that meet a condition?
Thanks.
Pete
Tables - HR = Patiets; OT = Orders
Output desired - list of patients with primary order (rank=1) or patients with no orders
Database setup - HR left outer join OT
Record selection criteria - {hr.pat_stat} = 'Active' and {hr.pat_type} = 'Supplies Only' and (isnull({ot.rank}) or {ot.rank} = 1)
This creates the following SQL in crystal -
SELECT "HR"."LAST_NAME", "HR"."PAT_TYPE", "HR"."PAT_STAT", "OT"."RANK", "HR"."FIRST_NAME"
FROM "CPR_SQL"."dbo"."HR" "HR" LEFT OUTER JOIN "CPR_SQL"."dbo"."OT" "OT" ON "HR"."MRN"="OT"."MRN"
WHERE "HR"."PAT_STAT"='Active' AND "HR"."PAT_TYPE"='Supplies Only' AND ("OT"."RANK" IS NULL OR "OT"."RANK"=1)
Problem - the patients without any orders do not appear.
I copy this into Enterprise Manager and they appear with a rank = null.
Why are they not in my report?
In summary - how do I join two tables where I include all the records in the left table and the records in the right table that meet a condition?
Thanks.
Pete