I know you are trying here but you have got to test these scripts if you want help. At this point your ddl is string across a number of posts and the queries you have continue to reference columns that don't exist.
Now that you posted the Facility table I tried to run just the query that you use to populate your cursor (I removed the date check for now just to see what your query looks like).
SELECT Distinct T.ApptID,Year,Month ,
FirstofMonth,TimeStampId,
SUM(CONVERT(decimal(18,0),DATEPART(MI,TimeStamp))) AS TotalDuration,
COUNT(A.ApptCode) As NumOfAppts,
f.FacilityID,
DoctorID,
GetDate()as CurrentDate
FROM t_Facility f INNER JOIN
t_Appointment A ON A.FacilityID = f.FacilityID INNER JOIN
t_Appointment_TimeStamp T on T.ApptID = A.ApptID
GROUP BY T.ApptID,f.FacilityID,DoctorID, YEAR, Month,FirstofMonth,TimeStampId
Here is what I get.
Msg 207, Level 16, State 1, Line 9
Invalid column name 'FacilityID'.
Msg 207, Level 16, State 1, Line 11
Invalid column name 'DoctorID'.
Msg 207, Level 16, State 1, Line 11
Invalid column name 'YEAR'.
Msg 207, Level 16, State 1, Line 11
Invalid column name 'Month'.
Msg 207, Level 16, State 1, Line 11
Invalid column name 'FirstofMonth'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'Year'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'Month'.
Msg 207, Level 16, State 1, Line 2
Invalid column name 'FirstofMonth'.
Msg 207, Level 16, State 1, Line 6
Invalid column name 'DoctorID'.
Please post all of you code in a single post along with sample data. Before you post it please load it into a test database and make sure it works.