select
pt.Last_Name_M0040 AS Last_Name, pt.First_Name_M0040 AS First_Name,
auth.Auth_ID,
auth.Patient_Id,
auth.PatientPayer_Id,
auth.Revenue_Code,
auth.StartDate,
auth.EndDate
from #Request.prefix_db_agency#.authorizations auth ,
#Request.prefix_db_agency#.authorizations_details auth_detail,
#Request.prefix_db_agency#.patient pt where
auth.Auth_ID = auth_detail.Auth_ID and
pt.Patient_Id = auth.Patient_Id and
auth.Patient_Id = #url.id# and auth_detail.ScheduleItems_ID is null
select PayName from #Request.prefix_db_agency#.Payer where Payer_Id in
(
select Payer_Id from #Request.prefix_db_agency#.patientpayer where PatientPayer_Id = '#GetList.PatientPayer_Id#'
)
invalid request