SELECT Admit_ID FROM #Request.prefix_db_agency#.pAssessments WHERE Assmt_ID = AND status = 0 LIMIT 1 SELECT pSchedules.Schedule_ID, pSchedules.Skill AS Sched_Skill, pAuths.Skill AS Auth_Skill, schedRev.HCPCS AS Schedule_HCPCS, pSchedules.Visit_Type, pSchedules.Followup_visit, pSchedules.Missed, pSchedules.Assmt_ID, DATE(pSchedules.Visit_Date) AS Visit_Date, DATE_FORMAT(DATE(pSchedules.Visit_Date), '%m/%d/%Y') AS VisitDate FROM #Request.prefix_db_agency#.pSchedules LEFT OUTER JOIN #Request.prefix_db_agency#.pAuths ON pAuths.Auth_ID = pSchedules.Auth_ID AND pAuths.status = 0 LEFT OUTER JOIN #Request.prefix_db_agency#.pRevenue_Code schedRev ON schedRev.Rev_CodeID = pSchedules.HCPCS_ID AND schedRev.status = 0 WHERE pSchedules.Patient_ID = AND pSchedules.status = 0 AND DATE(pSchedules.Visit_Date) >= AND DATE(pSchedules.Visit_Date) <= AND ( pSchedules.Assmt_ID IN ( SELECT a.Assmt_ID FROM #Request.prefix_db_agency#.pAssessments a WHERE a.Admit_ID = AND a.Patient_ID = AND a.status = 0 ) OR ( IFNULL(pSchedules.Assmt_ID, 0) = 0 AND IFNULL(pAuths.Assmt_ID, 0) IN ( SELECT a2.Assmt_ID FROM #Request.prefix_db_agency#.pAssessments a2 WHERE a2.Admit_ID = AND a2.Patient_ID = AND a2.status = 0 ) ) ) SELECT * FROM GetScheduledvisits WHERE (Missed = 0 OR Missed IS NULL)
 
#MonthAsString(month)# #year#
 
#Left(DayOfWeekAsString(LoopDay), attributes.DayLetter)#
#DateInMonth#