Suresh B. (8/6/2012)
Try this:
UPDATE a
SET masuk = b.datang
from @FirstTable a
inner join
(select userid,convert(date,CHECKTIME,103) tgl,convert(VARCHAR(5),min(CHECKTIME),14) datang,convert(VARCHAR(5),MAX(CHECKTIME),14) selesai from CHECKINOUT
WHERE convert(date,CHECKTIME,103) >= @sdate and convert(date,CHECKTIME,103) <= @edate
group by userid,convert(date,CHECKTIME,103)) as...