I want to update the records in my table using CTE. And I've been trying with the insert function using CTE and it's working. This is my query with the insert function:
; WITH CTE AS
(
SELECT *, RN = ROW_NUMBER() OVER (PARTITION BY NIP, NAME, DEPARTMENT ORDER BY DATEATTEND)
FROM DAILYDATA
)
INSERT INTO DAILYDATAWH (NIP, NAME, DEPARTMENT, STATUSIN, STATUSOUT)
SELECT NIP, NAME, DEPARTMENT, STATUSIN = MIN(DATEATTEND), STATUSOUT = MAX(DATEATTEND)
FROM CTE
GROUP BY NIP, NAME, DEPARTMENT, (RN - 1) / 2
How to change that with the update function?
i want to change to update function because when i use insert function,the previous data that already exists in DAILYDATA
appear again
This is table DAILYDATA
This is table DAILYDATAWH