ALTER TABLE dbo.VS4TEmpSlipDoc
	DROP CONSTRAINT IF EXISTS VS4TEmployeeVS4TEmpSlipDoc
GO
CREATE TABLE dbo.Tmp_VS4TEmpSlipDoc
	(
	TEpsNo nvarchar(30) NOT NULL,
	TEpsCheckGroup int NOT NULL,
	TEpsDate datetime NULL,
	TEpsRefNo nvarchar(30) NULL,
	TEpsTEmpCode nvarchar(30) NULL,
	TEpsIsAdmin smallint NULL,
	TEpsEmployeeCode nvarchar(30) NULL,
	TEpsEmployeeName nvarchar(50) NULL,
	TEpsEmployeeType nvarchar(50) NULL,
	TEpsBalanceFlag smallint NULL,
	TEpsTSAPTEmTCode nvarchar(30) NULL,
	TEpsTSaPDate datetime NULL,
	TEpsSalaryPeriod nvarchar(50) NULL,
	TEpsDivision nvarchar(50) NULL,
	TEpsDepartment nvarchar(50) NULL,
	TEpsSection nvarchar(50) NULL,
	TEpsStartDate datetime NULL,
	TEpsEndDate datetime NULL,
	TEpsOTStartDate datetime NULL,
	TEpsOTEndDate datetime NULL,
	TEpsTotalWorkDay smallint NULL,
	TEpsTotalLeaveHDay smallint NULL,
	TEpsTotalDebit float(53) NULL,
	TEpsTotalCredit float(53) NULL,
	TEpsTotalSave float(53) NULL,
	TEpsNetTotal float(53) NULL,
	TEpsSalaryBase float(53) NULL,
	TEpsSalaryQuantity float(53) NULL,
	TEpsSalaryCalc float(53) NULL,
	TEpsPTAXBase float(53) NULL,
	TEpsPTAX float(53) NULL,
	TEpsPTAXOffice float(53) NULL,
	TEpsPTAXAmass float(53) NULL,
	TEpsSTAXBase float(53) NULL,
	TEpsSTAX float(53) NULL,
	TEpsSTAXOffice float(53) NULL,
	TEpsSTAXAmass float(53) NULL,
	TEpsSFUNDBase float(53) NULL,
	TEpsSFUND float(53) NULL,
	TEpsSFUNDOffice float(53) NULL,
	TEpsSFUNDAmass float(53) NULL,
	TEpsFUNDBase float(53) NULL,
	TEpsFUND float(53) NULL,
	TEpsFUNDOffice float(53) NULL,
	TEpsFUNDAmass float(53) NULL,
	TEpsFINT float(53) NULL,
	TEpsFINTOffice float(53) NULL,
	TEpsFINTAmass float(53) NULL,
	TEpsFINTAmassOff float(53) NULL,
	TEpsAmassRevenue float(53) NULL,
	TEpsAmassExpense float(53) NULL,
	TEpsPaymentType smallint NULL,
	TEpsPaymentName nvarchar(50) NULL,
	TEpsTBnkCode nvarchar(30) NULL,
	TEpsTBBrCode nvarchar(30) NULL,
	TEpsBankName nvarchar(100) NULL,
	TEpsBankBranch nvarchar(100) NULL,
	TEpsBankAccType nvarchar(50) NULL,
	TEpsBankAccName nvarchar(160) NULL,
	TEpsBankAccNo nvarchar(30) NULL,
	TEpsDateBank datetime NULL,
	TEpsDescription nvarchar(150) NULL,
	TEpsCreateCode nvarchar(30) NULL,
	TEpsCreateBy nvarchar(140) NULL,
	TEpsCreateDate datetime NULL,
	TEpsEditCode nvarchar(30) NULL,
	TEpsEditBy nvarchar(140) NULL,
	TEpsEditDate datetime NULL,
	TEpsConfirmStatus smallint NULL,
	TEpsConfirmBy nvarchar(140) NULL,
	TEpsConfirmDate datetime NULL,
	TEpsApproveStatus smallint NULL,
	TEpsApproveBy nvarchar(140) NULL,
	TEpsApproveDate datetime NULL,
	TEpsApproveNote nvarchar(80) NULL,
	TEpsConfidential smallint NULL,
	TEpsCancelStatus smallint NULL,
	TEpsCancelNo nvarchar(30) NULL,
	TEpsCancelBy nvarchar(140) NULL,
	TEpsCancelDate datetime NULL,
	TEpsCancelNote nvarchar(80) NULL,
	TEpsFlag1 smallint NULL,
	TEpsFlag2 smallint NULL,
	TEpsFlag3 smallint NULL
	)  ON [PRIMARY]
GO
IF EXISTS(SELECT * FROM dbo.VS4TEmpSlipDoc)
	 EXEC('INSERT INTO dbo.Tmp_VS4TEmpSlipDoc (TEpsNo, TEpsCheckGroup, TEpsDate, TEpsRefNo, TEpsTEmpCode, TEpsIsAdmin, TEpsEmployeeCode, TEpsEmployeeName, TEpsEmployeeType, TEpsBalanceFlag, TEpsTSAPTEmTCode, TEpsTSaPDate, TEpsSalaryPeriod, TEpsDivision, TEpsDepartment, TEpsSection, TEpsStartDate, TEpsEndDate, TEpsOTStartDate, TEpsOTEndDate, TEpsTotalWorkDay, TEpsTotalLeaveHDay, TEpsTotalDebit, TEpsTotalCredit, TEpsTotalSave, TEpsNetTotal, TEpsSalaryBase, TEpsSalaryQuantity, TEpsSalaryCalc, TEpsPTAXBase, TEpsPTAX, TEpsPTAXOffice, TEpsPTAXAmass, TEpsSTAXBase, TEpsSTAX, TEpsSTAXOffice, TEpsSTAXAmass, TEpsSFUNDBase, TEpsSFUND, TEpsSFUNDOffice, TEpsSFUNDAmass, TEpsFUNDBase, TEpsFUND, TEpsFUNDOffice, TEpsFUNDAmass, TEpsFINT, TEpsFINTOffice, TEpsFINTAmass, TEpsFINTAmassOff, TEpsAmassRevenue, TEpsAmassExpense, TEpsPaymentType, TEpsPaymentName, TEpsTBnkCode, TEpsTBBrCode, TEpsBankName, TEpsBankBranch, TEpsBankAccType, TEpsBankAccName, TEpsBankAccNo, TEpsDateBank, TEpsDescription, TEpsCreateCode, TEpsCreateBy, TEpsCreateDate, TEpsEditCode, TEpsEditBy, TEpsEditDate, TEpsConfirmStatus, TEpsConfirmBy, TEpsConfirmDate, TEpsApproveStatus, TEpsApproveBy, TEpsApproveDate, TEpsApproveNote, TEpsConfidential, TEpsCancelStatus, TEpsCancelNo, TEpsCancelBy, TEpsCancelDate, TEpsCancelNote, TEpsFlag1, TEpsFlag2, TEpsFlag3)
		SELECT TEpsNo, CONVERT(int, TEpsCheckGroup), TEpsDate, TEpsRefNo, TEpsTEmpCode, TEpsIsAdmin, TEpsEmployeeCode, TEpsEmployeeName, TEpsEmployeeType, TEpsBalanceFlag, TEpsTSAPTEmTCode, TEpsTSaPDate, TEpsSalaryPeriod, TEpsDivision, TEpsDepartment, TEpsSection, TEpsStartDate, TEpsEndDate, TEpsOTStartDate, TEpsOTEndDate, TEpsTotalWorkDay, TEpsTotalLeaveHDay, TEpsTotalDebit, TEpsTotalCredit, TEpsTotalSave, TEpsNetTotal, TEpsSalaryBase, TEpsSalaryQuantity, TEpsSalaryCalc, TEpsPTAXBase, TEpsPTAX, TEpsPTAXOffice, TEpsPTAXAmass, TEpsSTAXBase, TEpsSTAX, TEpsSTAXOffice, TEpsSTAXAmass, TEpsSFUNDBase, TEpsSFUND, TEpsSFUNDOffice, TEpsSFUNDAmass, TEpsFUNDBase, TEpsFUND, TEpsFUNDOffice, TEpsFUNDAmass, TEpsFINT, TEpsFINTOffice, TEpsFINTAmass, TEpsFINTAmassOff, TEpsAmassRevenue, TEpsAmassExpense, TEpsPaymentType, TEpsPaymentName, TEpsTBnkCode, TEpsTBBrCode, TEpsBankName, TEpsBankBranch, TEpsBankAccType, TEpsBankAccName, TEpsBankAccNo, TEpsDateBank, TEpsDescription, TEpsCreateCode, TEpsCreateBy, TEpsCreateDate, TEpsEditCode, TEpsEditBy, TEpsEditDate, TEpsConfirmStatus, TEpsConfirmBy, TEpsConfirmDate, TEpsApproveStatus, TEpsApproveBy, TEpsApproveDate, TEpsApproveNote, TEpsConfidential, TEpsCancelStatus, TEpsCancelNo, TEpsCancelBy, TEpsCancelDate, TEpsCancelNote, TEpsFlag1, TEpsFlag2, TEpsFlag3 FROM dbo.VS4TEmpSlipDoc (HOLDLOCK TABLOCKX)')
GO
DROP TABLE dbo.VS4TEmpSlipDoc
GO
EXECUTE sp_rename N'dbo.Tmp_VS4TEmpSlipDoc', N'VS4TEmpSlipDoc', 'OBJECT'
GO
ALTER TABLE dbo.VS4TEmpSlipDoc ADD CONSTRAINT
	TEpsNo PRIMARY KEY CLUSTERED 
	(
	TEpsNo,
	TEpsCheckGroup
	) ON [PRIMARY]

GO
CREATE NONCLUSTERED INDEX PrimaryKey ON dbo.VS4TEmpSlipDoc
	(
	TEpsNo,
	TEpsCheckGroup
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TEpsCheckGroup ON dbo.VS4TEmpSlipDoc
	(
	TEpsCheckGroup
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TEpsTBBrCode ON dbo.VS4TEmpSlipDoc
	(
	TEpsTBBrCode
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TEpsTBnkCode ON dbo.VS4TEmpSlipDoc
	(
	TEpsTBnkCode
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TEpsTEmTCode ON dbo.VS4TEmpSlipDoc
	(
	TEpsTSAPTEmTCode
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TEpsTEsTAlias ON dbo.VS4TEmpSlipDoc
	(
	TEpsBalanceFlag
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TPADCreateCode ON dbo.VS4TEmpSlipDoc
	(
	TEpsCreateCode
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TPADEditBy ON dbo.VS4TEmpSlipDoc
	(
	TEpsEditBy
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TPADEditCode ON dbo.VS4TEmpSlipDoc
	(
	TEpsEditCode
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TSaPID ON dbo.VS4TEmpSlipDoc
	(
	TEpsTSaPDate
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX VS4TEmployeeVS4TEmpSlipDoc ON dbo.VS4TEmpSlipDoc
	(
	TEpsTEmpCode
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX VS4TEmpSlipPeriodVS4TEmpSlipDoc ON dbo.VS4TEmpSlipDoc
	(
	TEpsTSAPTEmTCode,
	TEpsTSaPDate
	) ON [PRIMARY]
GO
ALTER TABLE dbo.VS4TEmpSlipDoc WITH NOCHECK ADD CONSTRAINT
	VS4TEmployeeVS4TEmpSlipDoc FOREIGN KEY
	(
	TEpsTEmpCode
	) REFERENCES dbo.VS4TEmployee
	(
	TEmpCode
	) ON UPDATE CASCADE
	
GO

