
ALTER TABLE dbo.VS4TPOPTransMB
	DROP CONSTRAINT IF EXISTS VS4TPOPTransVS4TPOPTransMB
GO


CREATE TABLE dbo.Tmp_VS4TPOPTransMB
	(
	TPTBTPPDNo nvarchar(30) NOT NULL,
	TPTBBalanceNo nvarchar(30) NOT NULL,
	TPTBLn int NOT NULL,
	TPTBDate datetime NULL,
	TPTBType smallint NULL,
	TPTBTPdtCode nvarchar(50) NULL,
	TPTBCustom1 nvarchar(30) NULL,
	TPTBCustom2 nvarchar(150) NULL,
	TPTBCustom3 nvarchar(150) NULL,
	TPTBCustom4 nvarchar(150) NULL,
	TPTBCustom5 nvarchar(150) NULL,
	TPTBFactoryCode nvarchar(50) NULL,
	TPTBProductName nvarchar(150) NULL,
	TPTBBalanceUnit nvarchar(30) NULL,
	TPTBWHeadQty nvarchar(50) NULL,
	TPTBWQuantity float(53) NULL,
	TPTBTPScCode nvarchar(30) NULL,
	TPTBDisRemark nvarchar(100) NULL,
	TPTBWDisQtyTxt nvarchar(50) NULL,
	TPTBWDisQtyPC float(53) NULL,
	TPTBWDisQtyFix float(53) NULL,
	TPTBWDisQtyTotal float(53) NULL,
	TPTBWDisQtyTxt2 nvarchar(50) NULL,
	TPTBWDisQtyPC2 float(53) NULL,
	TPTBWDisQtyFix2 float(53) NULL,
	TPTBWDisQtyTotal2 float(53) NULL,
	TPTBWNetQty float(53) NULL,
	TPTBQuantity float(53) NULL,
	TPTBTUntCode nvarchar(50) NULL,
	TPTBQuantity2 float(53) NULL,
	TPTBTUntCode2 nvarchar(50) NULL,
	TPTBQuantity3 float(53) NULL,
	TPTBTUntCode3 nvarchar(50) NULL,
	TPTBUnitType smallint NULL,
	TPTBUnit2Ratio real NULL,
	TPTBUnit3Ratio real NULL,
	TPTBUnitCalc smallint NULL,
	TPTBQuantityCalc float(53) NULL,
	TPTBPerQuantity float(53) NULL,
	TPTBCurCode nvarchar(30) NULL,
	TPTBPrice money NULL,
	TPTBUnitPrice money NULL,
	TPTBSubTotal money NULL,
	TPTBDiscountText nvarchar(30) NULL,
	TPTBDiscountPC real NULL,
	TPTBDiscountFix money NULL,
	TPTBDiscountTotal money NULL,
	TPTBNetAmount money NULL,
	TPTBAmount money NULL,
	TPTBUnitFactor float(53) NULL,
	TPTBAcceptErrorPC real NULL,
	TPTBTaxType smallint NULL,
	TPTBAmountVAT money NULL,
	TPTBAmountWTAX money NULL,
	TPTBAutoSTD smallint NULL,
	TPTBStandardCost money NULL,
	TPTBMargin real NULL,
	TPTBSaleMargin money NULL,
	TPTBAutoPrice smallint NULL,
	TPTBPromotionType nvarchar(15) NULL,
	TPTBFreeCode nvarchar(30) NULL,
	TPTBFreeNumber float(53) NULL,
	TPTBDescription nvarchar(255) NULL,
	TPTBSourceNo nvarchar(30) NULL,
	TPTBSourceLn int NULL,
	TPTBSourceDate datetime NULL,
	TPTBSourceCode1 nvarchar(30) NULL,
	TPTBSourceCode2 nvarchar(30) NULL,
	TPTBStockTotal float(53) NULL,
	TPTBPRArrear float(53) NULL,
	TPTBEOQ float(53) NULL,
	TPTBTotalDelivery float(53) NULL,
	TPTBTotalDelivery2 float(53) NULL,
	TPTBTotalDelivery3 float(53) NULL,
	TPTBTotalArrear float(53) NULL,
	TPTBTotalArrear2 float(53) NULL,
	TPTBTotalArrear3 float(53) NULL,
	TPTBMapTPdtCode nvarchar(30) NULL,
	TPTBMapTPdtName nvarchar(150) NULL,
	TPTBMapTUntCode nvarchar(50) NULL,
	TPTBMapTUntCode2 nvarchar(30) NULL,
	TPTBMapTUntCode3 nvarchar(30) NULL,
	TPTBStatus smallint NULL,
	TPTBAlerted smallint NULL,
	TPTBCreateCode nvarchar(30) NULL,
	TPTBCreateBy nvarchar(150) NULL,
	TPTBCreateDate datetime NULL,
	TPTBFlag1 smallint NULL,
	TPTBFlag2 smallint NULL,
	TPTBFlag3 smallint NULL
	)  ON [PRIMARY]
GO
IF EXISTS(SELECT * FROM dbo.VS4TPOPTransMB)
	 EXEC('INSERT INTO dbo.Tmp_VS4TPOPTransMB (TPTBTPPDNo, TPTBBalanceNo, TPTBLn, TPTBDate, TPTBType, TPTBTPdtCode, TPTBCustom1, TPTBCustom2, TPTBCustom3, TPTBCustom4, TPTBCustom5, TPTBFactoryCode, TPTBProductName, TPTBBalanceUnit, TPTBWHeadQty, TPTBWQuantity, TPTBTPScCode, TPTBDisRemark, TPTBWDisQtyTxt, TPTBWDisQtyPC, TPTBWDisQtyFix, TPTBWDisQtyTotal, TPTBWDisQtyTxt2, TPTBWDisQtyPC2, TPTBWDisQtyFix2, TPTBWDisQtyTotal2, TPTBWNetQty, TPTBQuantity, TPTBTUntCode, TPTBQuantity2, TPTBTUntCode2, TPTBQuantity3, TPTBTUntCode3, TPTBUnitType, TPTBUnit2Ratio, TPTBUnit3Ratio, TPTBUnitCalc, TPTBQuantityCalc, TPTBPerQuantity, TPTBCurCode, TPTBPrice, TPTBUnitPrice, TPTBSubTotal, TPTBDiscountText, TPTBDiscountPC, TPTBDiscountFix, TPTBDiscountTotal, TPTBNetAmount, TPTBAmount, TPTBUnitFactor, TPTBAcceptErrorPC, TPTBTaxType, TPTBAmountVAT, TPTBAmountWTAX, TPTBAutoSTD, TPTBStandardCost, TPTBMargin, TPTBSaleMargin, TPTBAutoPrice, TPTBPromotionType, TPTBFreeCode, TPTBFreeNumber, TPTBDescription, TPTBSourceNo, TPTBSourceLn, TPTBSourceDate, TPTBSourceCode1, TPTBSourceCode2, TPTBStockTotal, TPTBPRArrear, TPTBEOQ, TPTBTotalDelivery, TPTBTotalDelivery2, TPTBTotalDelivery3, TPTBTotalArrear, TPTBTotalArrear2, TPTBTotalArrear3, TPTBMapTPdtCode, TPTBMapTPdtName, TPTBMapTUntCode, TPTBMapTUntCode2, TPTBMapTUntCode3, TPTBStatus, TPTBAlerted, TPTBCreateCode, TPTBCreateBy, TPTBCreateDate, TPTBFlag1, TPTBFlag2, TPTBFlag3)
		SELECT TPTBTPPDNo, TPTBBalanceNo, TPTBLn, TPTBDate, TPTBType, TPTBTPdtCode, TPTBCustom1, TPTBCustom2, TPTBCustom3, TPTBCustom4, TPTBCustom5, TPTBFactoryCode, TPTBProductName, TPTBBalanceUnit, TPTBWHeadQty, TPTBWQuantity, TPTBTPScCode, TPTBDisRemark, TPTBWDisQtyTxt, TPTBWDisQtyPC, TPTBWDisQtyFix, TPTBWDisQtyTotal, TPTBWDisQtyTxt2, TPTBWDisQtyPC2, TPTBWDisQtyFix2, TPTBWDisQtyTotal2, CONVERT(float(53), TPTBWNetQty), TPTBQuantity, TPTBTUntCode, TPTBQuantity2, TPTBTUntCode2, TPTBQuantity3, TPTBTUntCode3, TPTBUnitType, TPTBUnit2Ratio, TPTBUnit3Ratio, TPTBUnitCalc, TPTBQuantityCalc, TPTBPerQuantity, TPTBCurCode, TPTBPrice, TPTBUnitPrice, TPTBSubTotal, TPTBDiscountText, TPTBDiscountPC, TPTBDiscountFix, TPTBDiscountTotal, TPTBNetAmount, TPTBAmount, TPTBUnitFactor, TPTBAcceptErrorPC, TPTBTaxType, TPTBAmountVAT, TPTBAmountWTAX, TPTBAutoSTD, TPTBStandardCost, TPTBMargin, TPTBSaleMargin, TPTBAutoPrice, TPTBPromotionType, TPTBFreeCode, TPTBFreeNumber, TPTBDescription, TPTBSourceNo, TPTBSourceLn, TPTBSourceDate, TPTBSourceCode1, TPTBSourceCode2, TPTBStockTotal, TPTBPRArrear, TPTBEOQ, TPTBTotalDelivery, TPTBTotalDelivery2, TPTBTotalDelivery3, TPTBTotalArrear, TPTBTotalArrear2, TPTBTotalArrear3, TPTBMapTPdtCode, TPTBMapTPdtName, TPTBMapTUntCode, TPTBMapTUntCode2, TPTBMapTUntCode3, TPTBStatus, TPTBAlerted, TPTBCreateCode, TPTBCreateBy, TPTBCreateDate, TPTBFlag1, TPTBFlag2, TPTBFlag3 FROM dbo.VS4TPOPTransMB (HOLDLOCK TABLOCKX)')
GO
DROP TABLE dbo.VS4TPOPTransMB
GO
EXECUTE sp_rename N'dbo.Tmp_VS4TPOPTransMB', N'VS4TPOPTransMB', 'OBJECT'
GO
ALTER TABLE dbo.VS4TPOPTransMB ADD CONSTRAINT
	TPTBTPPDNo PRIMARY KEY CLUSTERED 
	(
	TPTBTPPDNo,
	TPTBBalanceNo,
	TPTBLn
	) ON [PRIMARY]

GO
CREATE NONCLUSTERED INDEX PrimaryKey ON dbo.VS4TPOPTransMB
	(
	TPTBTPPDNo,
	TPTBBalanceNo,
	TPTBLn
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TCKMMapTPdtCode ON dbo.VS4TPOPTransMB
	(
	TPTBMapTPdtCode
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TCKMMapTUntCode ON dbo.VS4TPOPTransMB
	(
	TPTBMapTUntCode
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TPOBMapTPdtCode ON dbo.VS4TPOPTransMB
	(
	TPTBMapTPdtName
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TPSMUnitFactor ON dbo.VS4TPOPTransMB
	(
	TPTBUnitFactor
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TPTBCreateBy ON dbo.VS4TPOPTransMB
	(
	TPTBCreateDate
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TPTBPriceTUntCode ON dbo.VS4TPOPTransMB
	(
	TPTBCurCode
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TPTBTPScCode ON dbo.VS4TPOPTransMB
	(
	TPTBTPScCode
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TPTBTPScCode1 ON dbo.VS4TPOPTransMB
	(
	TPTBDisRemark
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TPTBUserCode ON dbo.VS4TPOPTransMB
	(
	TPTBCreateCode
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TPTBUserCode1 ON dbo.VS4TPOPTransMB
	(
	TPTBCreateBy
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TPWBID ON dbo.VS4TPOPTransMB
	(
	TPTBLn
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TSOBFactoryCode ON dbo.VS4TPOPTransMB
	(
	TPTBFactoryCode
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TSOBFreeCode ON dbo.VS4TPOPTransMB
	(
	TPTBFreeCode
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TSOBSourceCode1 ON dbo.VS4TPOPTransMB
	(
	TPTBSourceCode1
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TSOBSourceCode2 ON dbo.VS4TPOPTransMB
	(
	TPTBSourceCode2
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TSOBSourceNo ON dbo.VS4TPOPTransMB
	(
	TPTBSourceNo
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TSOBTPOSCode ON dbo.VS4TPOPTransMB
	(
	TPTBTPdtCode
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TSOBTUntCode ON dbo.VS4TPOPTransMB
	(
	TPTBTUntCode
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TSOBTUntCode2 ON dbo.VS4TPOPTransMB
	(
	TPTBTUntCode2
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TSOBTUntCode3 ON dbo.VS4TPOPTransMB
	(
	TPTBTUntCode3
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TSOBType ON dbo.VS4TPOPTransMB
	(
	TPTBType
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TTfMID ON dbo.VS4TPOPTransMB
	(
	TPTBTPPDNo
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX VS4TPOPTransVS4TPOPTransMB ON dbo.VS4TPOPTransMB
	(
	TPTBTPPDNo
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX VS4TProductVS4TPOPTransMB ON dbo.VS4TPOPTransMB
	(
	TPTBTPdtCode
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX VS4TUnitVS4TPOPTransMB ON dbo.VS4TPOPTransMB
	(
	TPTBTUntCode
	) ON [PRIMARY]
GO
ALTER TABLE dbo.VS4TPOPTransMB WITH NOCHECK ADD CONSTRAINT
	VS4TPOPTransVS4TPOPTransMB FOREIGN KEY
	(
	TPTBTPPDNo
	) REFERENCES dbo.VS4TPOPTrans
	(
	TPPDNo
	) ON UPDATE CASCADE
	
GO

