I have two tables in the same server
How to count present/absent from attendance table in (employee database) and update that count info payroll table in (payroll database) on the same server?
Please help me to solve this problem.
Attendance table:
Payroll table:
Try this
;WITH X
AS(
SELECT
EmpId
,COUNT(EntryType) 'P_Count'
FROM
dbo.Attendance
WHERE
EntryType = 'P'
GROUP BY
EmpId
)
UPDATE
P
SET
P.Presents = X.P_Count
FROM
dbo.PayRoll P
INNER JOIN
X A ON A.EmpId = P.EmpId
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.