SELECT d.DEPTID AS [COMP_CODE], u.Badgenumber AS [EMP_CODE], cio.CHECKTYPE AS [TYPE_INOUT],
cio.CHECKTIME AS [WORKDATE], DATEPART(hh,CHECKTIME) AS [TIME_INOUT_HR],
DATEPART(n,CHECKTIME) AS [TIME_INOUT_MM], cio.SENSORID AS [TERMINAL]
INTO dbo.CONVERT_DATA4
FROM DEPARTMENTS AS d
JOIN USERINFO AS u ON d.DEPTID = u.DEFAULTDEPTID
JOIN CHECKINOUT AS cio ON cio.USERID = u.USERID
คำสั่งนี้รันซ้ำได้ output ออกเป็นไฟล์ .rtp (เปลี่ยนจาก Results to Grid เป็น Results to File)
Code
SELECT d.DEPTID AS [COMP_CODE], u.Badgenumber AS [EMP_CODE], cio.CHECKTYPE AS [TYPE_INOUT],
cio.CHECKTIME AS [WORKDATE], DATEPART(hh,CHECKTIME) AS [TIME_INOUT_HR],
DATEPART(n,CHECKTIME) AS [TIME_INOUT_MM], cio.SENSORID AS [TERMINAL]
INTO CONVERT_DATA
FROM DEPARTMENTS AS d
JOIN USERINFO AS u ON d.DEPTID = u.DEFAULTDEPTID
JOIN CHECKINOUT AS cio ON cio.USERID = u.USERID
ALTER TABLE CONVERT_DATA
ADD IM_TO_HRMS varchar(1) NOT NULL DEFAULT 'N'
ALTER TABLE CONVERT_DATA
ADD MODIFY_BY varchar(10) NOT NULL DEFAULT 'TAFF'
ALTER TABLE CONVERT_DATA
ADD MODIFY_DATE datetime NOT NULL DEFAULT GETDATE()
SELECT *
FROM CONVERT_DATA
DROP TABLE CONVERT_DATA
ถ้าได้โค้ดโปรแกรม ที่ทำให้ง่ายกว่านี้ โดยได้ output โดยไม่ต้องเปิด Microsoft SQL Server เลย จะดีมากๆๆๆ
CREATE VIEW vw_TEST
as
SELECT d.DEPTID AS [COMP_CODE], u.Badgenumber AS [EMP_CODE], cio.CHECKTYPE AS [TYPE_INOUT],
cio.CHECKTIME AS [WORKDATE], DATEPART(hh,CHECKTIME) AS [TIME_INOUT_HR],
DATEPART(n,CHECKTIME) AS [TIME_INOUT_MM], cio.SENSORID AS [TERMINAL]
INTO CONVERT_DATA
FROM DEPARTMENTS AS d
JOIN USERINFO AS u ON d.DEPTID = u.DEFAULTDEPTID
JOIN CHECKINOUT AS cio ON cio.USERID = u.USERID
SELECT * FROM vw_TEST