Here's the fixed code:
SET @tableHTML = N'<table border="1">' +
N'<tr><th>Key</th><th>TO Type</th><th>Employee</th><th>TO Hour(s)</th>' +
N'<th>Create Date</th><th>Create By</th><th>Comment</th><th>Earned</th></tr>' +
CAST(( SELECT SnapshotBefore.query(
'for $b in
/DocumentElement/Accrual
return...