January 10, 2008 at 4:19 am
Hi i am, just wondering if anyone could help me with an sql query, there is one main table MedicalReferral and it joins 3 others that may have matching rows or not, i need to display View is there are matching rows or else No Report i have written this sql but it doesnt work any help would be appreciated
Thanks in advance
Tim
Select
case
when rr.ReferralID is null then 'No Report1'
when rrp.ReferralID is null then 'No Report2'
when fluid.ReferralID is null then 'No Report3'
else 'View'
end as 'Report',
rr.ReferralID,
rrp.ReferralID,
fluid.ReferralID
From MedicalReferral mr
Left Join ReferralReport rr on rr.ReferralID = mr.ID
Left Join ReferralReportPathlab rrp on rrp.ReferralID = mr.ID
Left Join ReferralReportJointFluidMicroscopy fluid on fluid.ReferralID = mr.ID
January 10, 2008 at 4:31 am
What do you mean when you say it doesn't work? Does it give an error message, or does it just not return the results you expect? Please provide table structure for each table in the form of CREATE TABLE statements, sample data in the form of INSERT statements, and the results you expect to see given that sample data.
Thanks
John
January 10, 2008 at 5:26 am
thanks for ur reply but its actually ok now i managed to figure it out i just changed the case statement to be
case
when rr.ReferralID is not null then 'View'
when rrp.ReferralID is not null then 'View'
when fluid.ReferralID is not null then 'View'
else 'No Report'
Thanks again
Tim
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply