I have designed the following query
SELECT
v.visitid,
CASE
WHEN vd.DocType = 1 THEN 'y' ELSE 'n'
END as 'FinalReportAttached'
,CASE
WHEN vd.DocType = 13 THEN 'y' ELSE 'n'
END as 'InspectorReportAttached'
,CASE
WHEN vd.DocType = 2 THEN 'y' ELSE 'n'
END as 'Co-ordReportAttached'
FROM Visits v
INNER JOIN VisitDocs vd on vd.VisitID = v.VisitID
WHERE v.VisitID = 79118
I like to show results in one row. If report is there then 'y' and if not then 'n' .
There is a one to manay relation b/w visit and visitdoc table. Visitdoc can have many different docs for one visit. I need to check if visitdoc has doctype 1,3 or 12 against each visit then say yes otherwise no.
visitID |FinalReport |InspectorReport |Co-ordReport
------------------------------------------------
79118 |n |y |y