Somthing like this .. SELECTRptBilling.ItemType,Patient.PatientLNPrograms.ProgramDescription,ARBatches.ARBatch,Patient.PatientFN,RptBilling.BillPatientID,Case When BillFormats.BillFormatDescription IS NULL Then(Select BillFormats1.BillFormatDescriptionFROM RptBilling RptBilling1 INNER JOIN BillPatients BillPatients1ON RptBilling1.BillPatientID = BillPatients1.BillPatientIDINNER JOIN BillPatients BillPatients ON BillPatients.BillPatientID = BillPatients1.BillPatientIDINNER JOIN BTI.PatFundSource PatFundSource1ON BillPatients1.PatFundSourceID = PatFundSource1.PatFundSourceIDINNER JOIN BTI.ReimbPlans ReimbPlans1ON PatFundSource1.ReimbPlansID = ReimbPlans1.ReimbPlansIDINNER JOIN BTI.BillFormats BillFormats1 ON ReimbPlans1.BillFormatID = BillFormats1.BillFormatIDWhere BillPatients.BillPatientID = BillPatients1.BillPatientID AND BillFormats.BillFormatDescription IS NULL)END,ElecFormats.ElecFormatDescriptionFROM (((BTI.RptBilling RptBilling INNER JOIN BTI.ARBatches ARBatches ON RptBilling.ARBatchID=ARBatches.ARBatchID) INNER JOIN BTI.PatAdmissions PatAdmissionsON RptBilling.AdmissionID=PatAdmissions.AdmissionID) INNER JOIN BTI.Patient Patient ON PatAdmissions.PatientID=Patient.PatientID) INNER JOINBTI.Programs Programs ON PatAdmissions.ProgramID=Programs.ProgramID INNER JOIN BTI.BillPatients BillPatients ON RptBilling.BillPatientID = BillPatients.BillPatientIDLEFT OUTER JOIN BTI.ReimbplanPaperFormats ReimbplanPaperFormats ON BillPatients.ReimbPlanPaperFormatID = ReimbPlanPaperFormats.ReimbPlanPaperFormatID LEFT OUTER JOINBTI.BillFormats BillFormats ON ReimbPlanPaperFormats.BillFormatID = BillFormats.BillFormatID LEFT OUTER JOIN BTI.ReimbplanElecFormats ReimbplanElecFormatsON BillPatients.ReimbPlanElecFormatID = ReimbPlanElecFormats.ReimbPlanElecFormatID LEFT OUTER JOINBTI.ElecFormats ElecFormats ON ReimbPlanElecFormats.ElecFormatID = ElecFormats.ElecFormatID
Just make sure that this Sub query returns one records per row... for the parent query (Select BillFormats1.BillFormatDescriptionFROM RptBilling RptBilling1 INNER JOIN BillPatients BillPatients1ON RptBilling1.BillPatientID = BillPatients1.BillPatientIDINNER JOIN BillPatients BillPatients ON BillPatients.BillPatientID = BillPatients1.BillPatientIDINNER JOIN BTI.PatFundSource PatFundSource1ON BillPatients1.PatFundSourceID = PatFundSource1.PatFundSourceIDINNER JOIN BTI.ReimbPlans ReimbPlans1ON PatFundSource1.ReimbPlansID = ReimbPlans1.ReimbPlansIDINNER JOIN BTI.BillFormats BillFormats1 ON ReimbPlans1.BillFormatID = BillFormats1.BillFormatIDWhere BillPatients.BillPatientID = BillPatients1.BillPatientID AND BillFormats.BillFormatDescription IS NULL)
If Debugging is the process of removing Bugs then i Guess programming should be process of Adding them.