What you would need to do is to add an
UPDATE
query to your procedure; probably the easiest way to do this would be create yet another CTE in your procedure to wrap that final
SELECT
and then
JOIN
it to your destination table within the aforementioned JOIN
As you have not provided the table schema for the destination only assumptions can be made which I really do not care to do, so I will only provide the basics. I am also not going to be check your prior code even though it is visibly questionable.
; WITH cteFinal AS (
select cte.EmpID,cte.EmpName
, d.ReportingDate,cte2.Date
, cte.OTEntitled
, CTE.Empcur
, CTE.Dhour
, cte.LTime
, cte2.INTIME
, cte2.OUTTIME
, cte2.[Hours]
, CASE
WHEN cte2.[Hours] >= 8 THEN 1
WHEN cte2.[Hours] = 0 THEN 0
WHEN cte2.[Hours] >= 6 THEN 0.5
END AS [Day]
, CASE
WHEN cte2.[Hours] > CTE.Dhour then cte2.[Hours] - CTE.Dhour
else 0
End as OT
, CASE
when cte.OTEntitled = 'Yes' AND cte2.[Hours] >= CTE.Dhour tHEN (( cte2.[Hours] - 8) * 100)
else 0
END AS OTAMount
, Convert(varchar(10), cte2.INTIME,108) as [Time]
, Case
When Convert(Time, cte2.INTIME,108) > cte.LTime Then 1
else 0
end as Late
from cte
Cross Apply Dates d
Left Join cte2 ON cte2.EmpId= cte.EmpID AND cte2.Date=d.ReportingDate
)
UPDATE dt
SET dt.[Date] = cF.[Date]
, dt.OTEntitled = cD.OTEntitled
FROM [DestinationTable] dt
LEFT JOIN cteFinal cF ON dt.EmpID = cF.EmpID