• Pardon my ignorance but, what does the % 7 do in the DATEADD(day, 6 - DATEDIFF(day, 6, ApptDt2) % 7, ApptDt2)?

    In this case the % is the modulo operator. It is returning the remainder of the value DATEADD(day, 6 - DATEDIFF(day, 6, ApptDt2) divided by 7. This value will be a number between 0 and 6.

    Here is a link to the MSDN entry for Modulo:

    http://msdn.microsoft.com/en-us/library/ms190279(v=sql.100).aspx