SELECT IFNULL(pli.slidenumber,'')slidenumber, pli.result_flag, pli.subcategoryid,if(im.Container=7,'', pli.sampleqty)sampleqty, pli.IsUrgent,pli.HistoCytoSampleDetail,(select name from employee_master where employee_id=pli.HistoCytoPerformingDoctor limit 1) Performingdoctor ,pli.test_id, pli.IsSampleCollected, pli.BarcodeNo,lt.PName,pli.ledgerTransactionNO,pli.patient_id,pli.`SampleTypeID`,pli.`SampleTypeName`,'' Formalin, pli.itemname, case when pli.IsSampleCollected='S' then 'lightyellow' when pli.IsSampleCollected='Y' then 'lightgreen' when pli.IsSampleCollected='R' then 'pink' else 'white' end rowcolor, case when pli.IsSampleCollected='S' then 'Pending' when pli.IsSampleCollected='Y' then 'Received' when pli.IsSampleCollected='R' then 'Rejected' else 'white' end `status`,im.Container reporttype, lt.panelname PanelName,im.RequiredAttachment,im.AttchmentRequiredAt, (SELECT COUNT(id) FROM document_detail WHERE LabNo=lt.ledgerTransactionNo) AttachmentCount ,DATE_FORMAT(pli.`Date`,'%d-%b-%Y %h:%i %p')RegDate,ifnull(DATE_FORMAT(pli.`SRADate`,'%d-%b-%Y %h:%i %p'),'')SRADate FROM patient_labinvestigation_opd pli INNER JOIN investigation_master im on im.investigation_ID=pli.investigation_ID INNER JOIN investigation_observationtype iot ON pli.investigation_ID=iot.investigation_ID INNER JOIN f_ledgertransaction lt ON lt.ledgerTransactionID=pli.ledgerTransactionID and pli.IsSampleCollected=@IsSampleCollected inner JOIN sample_logistic sl on sl.barcodeno=pli.barcodeno AND sl.`testid` = pli.`Test_ID` AND sl.isactive=1 AND sl.tocentreid=@CentreID AND sl.status='Received' AND sl.dtLogisticReceive >=@fromDate AND sl.dtLogisticReceive <=@toDate order by sl.`BarcodeNo`