select b.trn_sno, b.bill_date, b.bill_bno, b.pt_name, b.age, b.sex,
isnull(d.doct_nm,'') as doct_nm,case when b.chk_free=1 then b.amount else 0 end as b.amount,case when b.chk_free=1 then 0 else b.amount end as b.amount,
case when isnull( b.app_ref,0)=1 then (case when isnull(b.rec_ref,0)=1 then 'Refunded' else 'Approve for Refund' end ) else '' end FROM rec_all as b LEFT JOIN doctors as d ON b.doct_id=d.doct_id WHERE " & txtfld & " and " & _
"b.rw=0 and b.co_code='" & CoCode & "' ORDER BY b.rec_ref, b.bill_date, b.trn_sno