SELECT
EmpNum
,SUM(CASE WHEN PayType = 'REG' THEN Hours ELSE 0 END) Hours
,SUM(CASE WHEN PayType <> 'REG' THEN Hours ELSE 0 END) PTO
,MIN(StartDate) StartDate
,MAX(EndDate) EndDate
INTO #TempTable
FROM @Tmp GROUP BY EmpNum
Then if pay period 2 exist execute another
Select (80 - (Hours + PTO) ) AdjustHours From #TempTable
Else
do nothing