I am having issues understanding the SOURCETABLE table from this code:
CREATE PROCEDURE [ifc_tt].[SendTimeBalance]
AS
DECLARE @endOfPreviousMonth DATE;
DECLARE @now DATETIME= GETDATE();
SELECT @endOfPreviousMonth = EOMONTH(GETDATE(), -1);
WITH sourceTable
AS (SELECT w.EmployeeId AS corporateId,
w.Date AS date,
w.logaValue AS flextimeHours
FROM rpt_tt.DQC_TimeBalance AS w
WHERE w.Date <= @endOfPreviousMonth)
MERGE INTO ifc_tt.TimeBalance AS t
USING sourceTable AS s
ON t.corporateId = s.corporateId
AND t.date = s.date
WHEN NOT MATCHED BY TARGET
THEN
INSERT(corporateId,
date,
flextimeHours,
overtimeHours,
lastUpdate,
Comment)
VALUES
(s.corporateId,
s.date,
s.flextimeHours,
NULL,
@now,
NULL
)
WHEN MATCHED
THEN UPDATE SET
t.flextimeHours = s.flextimeHours,
t.lastUpdate = @now;
RETURN 0;
Usually, when I see temp tables, they start with an @ (see @endOfPreviousMonth).
But in this case, sourcetable is used without an @. Still I read it is similar to a temp table. What exactly is the difference here and how is it in this context here?
Thank you for your help :)