--! Cadacus, Inc - Solutions for SYSPRO SQL Upgrade Script



--! After executing, scroll through the SQL Manager results view.

--!  Any messages starting with ##### ERROR ##### or SQL error messages

--!  should be reported to your support organization for analysis.



--! Note: If SQL Replication is enabled, it can cause some of the changes

--!       in the script to generate errors. Replication should be disabled

--!       before executing.



--! Note: SYSPRO foreign keys or constraints on the EDI tables

--!       will cause the required changes to fail. Use EDIDropConstraints.sql

--!       to clear the keys and constraints before executing the update script.



--! This script will upgrade your Cadacus Solutions for SYSPRO tables



--! 2022-08-24 - New Columns    EDIReportDetail



--! 2022-06-27 - New column     EDIShipmentItem



--! 2022-06-15 - New column     EDIXRefAddress



--! 2022-04-25 - New columns    EDIAOMMaster



--! 2022-04-18 - New column     EDIAOMDetail



--! 2022-03-09 - New columns    EDIReportHeader

--!              New column     EDIXRefDiscount



--! 2022-03-02 - Alter column   EDIShipmentMaster



--! 2022-02-07 - New columns    EDINext

--!              Expand columns EDIXRefAccounts



--! 2022-01-20 - New columns    EDIXRefComPaths



--! 2022-01-18 - New columns    EDIAOMSelection



--! 2021-11-03 - Major change to EDIShipmentOrder to change primary key to a document number

--!              instead oof the sales order number

--!              This conversion can take longer then usual if the shipment tables are large.

--!              Any "ShipmentNumber" column has been renamed to "Shipment"

--!              Other columns have been renamed for consistancy

--!              Computed columns have been added for all renamed columns to allow reports ect.

--!              to continue to function.

--!              New Column     EDILabelDetail

--!              New Column     EDILabelMaster

--!              New Column     EDIShipmentAdd

--!              New Index      EDIShipmentAdd

--!              Rename Columns EDIShipmentItem

--!              New Column     EDIShipmentItem

--!              Rename Columns EDIShipmentLevel

--!              Rename Columns EDIShipmentMaster

--!              New Column     EDIShipmentMaster

--!              New Column     EDIShipmentOrder

--!              New Index      EDIShipmentOrder

--!              Rename Columns EDIShipmentOrdPak

--!              Rename Columns EDIShipmentPack

--!              Rename Columns EDIShipmentSerials

--!              Rename Columns EDIShipmentSplit

--!              Rename Columns EDIShipmentSplitPk

--!              Rename Columns EDIShipmentSplitSe

--!              Rename Columns EDIShipmentTare

--!              Rename Columns EDIShipmentUPSDtl

--!              Rename Columns EDIShipmentVfy

--!              New columns    EDIXRefDimensions



--! 2021-11-09 - New columns    EDIXRefDimensions



--! 2021-09-30 - New columns    EDIImportDetail



--! 2021-09-23 - New columns    EDIAOMAvailable



--! 2021-09-13 - New column     EDILPItems



--! 2021-08-02 - New column     EDIMasterDocument



--! 2021-07-16 - New Column     EDIXRefLocation



--! 2021-07-12 - New Column     EDIXRefContainer



--! 2021-05-26 - New column     EDIAOMAvailable

--!              New columns    EDIAOMDetail

--!              New columns    EDIAOMMaster

--!              New table      EDIAOMTransfers



--! 2021-04-13 - New column     EDIXRefAddress



--! 2021-04-11   New Table      EDIChangeDetail

--!              New Table      EDIChangeHeader



--! 2021-03-21 - New column     EDIShipmentItem

--!              New column     EDIAOMAvailable

--!              New column     EDIXRefAccounts 

--!              New columns    EDIXRefDimmensions



--! 2021-01-14 - New column     EDIXRefDimensions



--! 2020-12-15 - New column     EDILPItems



--! 2020-12-08 - New Index      EDIShipmentItem

--!              New column     EDIShipmentOrder

--!              Change column  EDIShipmentAdd

--!              New columns    EDIShipmentAdd



--! 2020-06-17 - New columns    EDIXRefAddress



--! 2020-04-12 - Change columns EDIPreferences



--! 2020-03-27 - New Columns    EDIXRefCarrierSCAC



--! 2020-01-24 - New Columns    EDILPMaster

--!              New Table      EDIReportDetail

--!              New Table      EDIReportHeader



--! 2019-11-28 - New Column     EDIXRefContainer



--! 2019-11-22 - New columns    EDIXRefDateTime



--! 2019-11-02 - New Column     EDIXRefContainer



--! 2019-07-23 - New Column     EDIXRefPrinters

--!              New Column     EDIXRefVerifyCntry



--! 2019-03-20 - New Column     EDILPMaster



--! 2019-02-25 - New Column     EDIShipmentMaster

--!              New Column     EDIShipmentOrder



--! 2019-01-21 - New Column     EDIXRefCharges



--! 2018-11-11 - New Column     EDIAOMDetail

--!              New Column     EDILPTracking

--!              New table      EDIXRefBinType



--! 2018-11-04 - New table      EDIDocuments



--! 2018-10-10 - New Column     EDIXRefCharges



--! 2018-10-06 - New Columns    EDIXRefPrinterSel



--! 2018-09-04 - New Column     EDILPTracking

--!              Expand Fields  EDIXRefChargeRef

--!              Expand Fields  EDIXRefCharges

--!              Expand Field   EDIShipmentMaster



--! 2018-08-23 - New table      EDIDocuments



--! 2018-08-21 - New Columns    EDIXRefPrinterSel



--! 2018-08-19 - New Columns    EDIAOMDetail



--! 2018-08-03 - New table      EDIXRefBinType

--! 2018-08-03 - New table      EDIXRefContainer



--! 2018-07-23 - Change column  EDIXRefDiscount



--! 2018-06-27 - New column     EDIShipmentPack



--! 2018-04-20 - New Column     EDIShipmentMaster

--!              New Column     EDIXRefPrinterSel



--! 2018-04-18 - New Column     EDIXRefAccounts



--! 2018-03-06 - New Column     EDIXRefLabel



--! 2018-03-01 - Change column  EDIXRefEmployees



--! 2018-01-23 - New column     EDIShipmentPack



--! 2018-01-16 - New column     EDIXRefAccounts

--!              New table      EDIXRefPrinterSel



--! 2018-01-15 - New column     EDIControl

--!              Remove columns EDIControl



--! 2018-01-29 - New column     EDIXRefServices

--!              New table      EDIXRefLists



--! 2018-01-23 - New table      EDIXRefTariff



--! 2017-12-03 - New Table      EDILctVerifyItem

--!              New Table      EDILctVerifyMaster



--! 2017-09-24 - New column     EDIPaymentMaster



--! 2017-09-19 - New Index      EDILPItems



--! 2017-07-20 - Change column  EDIMasterHandhelds



--! 2017-06-12 - New Columns    EDILPMaster



--! 2017-03-03 - New Column     EDIXRefDimensions



--! 2017-02-27 - New Columns    EDIShipmentTare

--!              New Column     EDIXRefFrghtClass



--! 2017-02-23 - New Columns    EDIShipmentItem

--!              New Columns    EDILPTracking



--! 2017-02-21 - Change Column  EDIXRefCarrierSCAC



--! 2017-02-15 - New Columns    EDILPMaster



--! 2017-01-09 - New Table      EDIXRefVerifyState

--!              New Table      EDIXRefVerifyCntry



--! 2016-12-16 - New Column     EDIExternalQueue    

--!              New Column     EDIExternalResp

--!              New Column     EDIExternalLog

--!              New Table      EDIMessages



--! 2016-12-11 - New Columns    EDIXRefChargeRef



--! 2016-11-28 - New Columns    EDIXRefCarrierSCAC



--! 2016-11-02 - New Table      EDIAOMAvailable



--! 2016-11-01 - New Columns    EDIXRefBin



--! 2016-10-11 - New Columns    EDIXRefBin



--! 2016-10-03 - New Column     EDIAOMMaster



--! 2016-08-30 - New Column     EDILabelMaster

--!              New Column     EDIXRefLabel

--!              Add column     EDIXRefDangerous



--! 2016-08-02 - New Columns    EDIShipmentItem

--!              New Columns    EDIShipmentPack

--!              Rename Column  EDIShipmentUPSDtl



--! 2016-07-24 - Change columns EDIMasterDocument

--!              Change columns EDIMasterPartner



--! 2016-07-17 - Add column     EDIXRefDangerous

--!              Add column     EDIShipmentUPSDtl



--! 2016-06-29 - Add column     EDIUPSPricing

--!              Add column     EDIXrefCharges



--! 2016-06-26 - Change columns EDIShipmentUPSDtl



--! 2016-05-09 - New Column     EDIAOMLocks

--!              New Column     EDIAOMMaster



--! 2016-04-18 - New Column     EDIShipmentSplitPk



--! 2016-03-29 - New columns    EDIXRefAddress

--!              New Table      EDIAOMDetail

--!              New Table      EDIAOMLocks

--!              New Table      EDIAOMMaster

--!              New Table      EDIAOMSelection

--!              New Table      EDIAOMSecondary



--! 2016-02-15 - Change Column  EDIShipmentUPSDtl



--! 2016-02-09 - Add Columns    EDIXrefEmployee



--! 2016-01-10 - New Table      EDIExternalLog

--!              New Table      EDIExternalQueue    

--!              New Table      EDIExternalResp    



--! 2015-10-20 - New Columns    EDIShipmentItem

--!              New Columns    EDILPTracking



--! 2015-10-12 - Change columns EDIShipmentAdd



--! 2015-09-02 - New Column     EDIShipmentPack

--!              New Column     EDIXRefDimensions



--! 2015-08-27 - New Columns    EDIXRefCarrierSCAC



--! 2015-01-07 - Change columns EDIReceiverOrder



--! 2014-12-18 - New Columns    EDIXRefDangerous

--!              New Columns    EDIXRefAccounts



--! 2014-12-15 - New Columns    EDIShipmentMaster

--!              New Columns    EDIXRefAccounts



--! 2014-11-03 - New Column     EDILPItems

--!              New Column     EDIShipmentSplitPk



--! 2014-09-24 - New Table      EDIXRefScripts



--! 2014-08-06 - New Column     EDIShipmentPack



--! 2014-07-14 - New column     EDIXrefComPaths



--! 2014-07-08 - New column     EDIXrefComPaths

--!            - New column     EDIXRefSegmentRpt



--! 2014-06-24 - New Column     EDIShipmentSplitPk



--! 2014-06-13 - New Columns    EDIShipmentVfy



--! 2014-05-26 - New Table      EDIShipmentVfyDtl

--!              New Table      EDIShipmentVfy

--!              New Columns    EDIXRefCharges



--! 2014-05-14 - New Columns    EDIShipmentMaster

--!              New Columns    EDIShipmentSplit



--! 2014-03-31 - New Columns    EDILPItems

--!              New Columns    EDILPMaster



--! 2014-02-18 - New Table      EDILPDetails

--!              New Table      EDILPItems

--!              New Table      EDILPMaster

--!              New Table      EDILPTracking

--!              New Columns    EDIShipmentItem

--!              New Columns    EDIShipmentTare

--!              New Indexes    EDIShipmentTare



--! 2013-12-31 - New columns    EDIShipmentOrder

--!              New index      EDIShipmentPack

--!              New index      EDIShipmentTare

--! 2013-12-11 - New columns    EDIXRefCarrierSCAC

--! 2013-11-16 - Add Columns    EDIXrefEmployee

--! 2013-09-22 - New Table      EDIShipmentSplitSe



--! 2013-06-10 - Upgrade of tables for SYSPRO 7

--!              Change columns EDIChanges

--!              Change columns EDIComments

--!              Change columns EDIDocsToProcess

--!              Change columns EDIImportDetail

--!              Change columns EDIJobIssueItem

--!              Change columns EDIJobIssueJob

--!              Change columns EDIJobIssueMaster

--!              Change columns EDIJournal

--!              Change columns EDILabelAddress

--!              Change columns EDILabelDetail

--!              Change columns EDILabelMaster

--!              Change columns EDILog

--!              Change columns EDIMasterDocument

--!              Change columns EDIMasterHandhelds

--!              Change columns EDIMasterPartner

--!              Change columns EDIMasterStations

--!              Change columns EDINotes

--!              Drop Table     EDIOrderIndex

--!              Change columns EDIPaymentDetail

--!              Change columns EDIPaymentIndex

--!              Change columns EDIPaymentMaster

--!              Change columns EDIPaymentStockDet

--!              Change columns EDIPkgInterface

--!              Change columns EDIPreferences

--!              Change columns EDIReceiverItem

--!              Change columns EDIReceiverPack

--!              Change columns EDIReceiverMaster

--!              Change columns EDIRelease

--!              Drop Table     EDIReplenishment

--!              Change columns EDIShipmentAdd

--!              Drop Table     EDIShipmentDHLMan

--!              Drop Table     EDIShipmentDHLPce

--!              Drop Table     EDIShipmentDHLShp

--!              Change columns EDIShipmentFedex

--!              Change columns EDIShipmentLock

--!              Change columns EDIShipmentMaster

--!              Change columns EDIShipmentMasterD

--!              Change columns EDIShipmentOrder

--!              Change columns EDIShipmentOrdPak

--!              Change columns EDIShipmentItem

--!              Change columns EDIShipmentPack

--!              Change columns EDIShipmentSerials

--!              Change columns EDIShipmentSplit

--!              Change columns EDIShipmentUPSBook

--!              Change columns EDIShipmentUPSDtl

--!              Change columns EDIShipmentUSPS

--!              Change columns EDITakeItem

--!              Change columns EDITakeMaster

--!              Change columns EDITracking

--!              Change columns EDIXRefBin

--!              Change columns EDIXRefCommissions

--!              Change columns EDIXRefChargeRef

--!              Change columns EDIXRefDiscount

--!              Change columns EDIXRefDimensions

--!              Drop Table     EDIXRefExtendedPrc

--!              Change columns EDIXRefEMailConfig

--!              Change columns EDIXRefEmployees

--!              Change columns EDIXRefLocation

--!              Change columns EDIXRefOrder

--!              Change columns EDIXRefPromotions

--!              Change columns EDIXRefQuestions

--!              Change columns EDIXRefSalesman

--!              Change columns EDIXRefShipVia

--!              Change columns EDIXRefSpecial

--!              Change columns EDIXRefStationAR

--!              Change columns EDIXRefUOM

--!              Change columns EDIXRefUPC

--!              Change columns EDIXRefWarehouse

--!              Drop Table     EDIDHLAccount

--!              Drop Table     EDIDHLPriceBreak

--!              Drop Table     EDIDHLPricing

--!              Drop Table     EDIDHLRedirect

--!              Drop Table     EDIDHLServicePSC

--!              Drop Table     EDIDHLValidVAS

--!              Drop Table     EDIDHLHolidays

--!              Drop Table     EDIDHLPriceKey

--!              Drop Table     EDIDHLHotCode

--!              Drop Table     EDIDHLDestMap

--!              Drop Table     EDIDHLOriginMap

--!              Drop Table     EDIDHLPostcode

--!              Drop Table     EDIDHLTransit

--!              Drop Table     EDIDHLService

--!              Drop Table     EDIDHLVasFee

--!              Drop Table     EDIDHLZone





--! 2013-05-10 - Add column     EDIXRefCharges

--!              Add column     EDIXRefSCAC   

--! 2013-05-08 - Add column     EDILabelPackage

--! 2013-04-29 - Add column     EDILabelPackage

--!              Add columns    EDIShipmentPack

--! 2013-02-19 - Add columns    EDILabelMaster

--! 2013-02-16 - Change columns EDIShipmentUPSDtl

--!              Change columns EDILabelMaster

--!              Change columns EDIShipmentPack

--! 2013-02-02 - New columns    EDIXRefLocation

--! 2013-01-24 - New index      EDIPaymentDetail 

--! 2013-01-10 - New column     EDIPaymentDetail

--!              New columns    EDIXRefAccounts



--! 2012-12-09 - New column     EDIMasterDocument

--!              New column     EDIXRefCharges

--! 2012-11-14 - New columns    EDIShipmentUPSDtl

--!              New columns    EDILabelPackage

--!              New Table      EDIXRefCFFTrans

--! 2012-08-27 - New columns    EDIXRefCarrierSCAC

--! 2012-07-21 - Change Columns EDIXRefStockSub

--!              New column     EDIXRefEMailRoutes

--!              New columns    EDILabelMaster

--! 2012-06-19 - Correct column EDIShipmentPack

--!              Correct column EDIReceiverPack

--!              New columns    EDILabelMaster

--! 2012-05-28 - New column     EDIShipmentUPSDtl

--!              Alter Column   EDIXRefCommissions

--!              New column     EDIXRefSCAC

--! 2012-05-17 - New Table      EDIJobIssueItem

--!              New Table      EDIJobIssueJob

--!              New Table      EDIJobIssueMaster

--! 2012-03-26 - New column     EDIXrefComPaths

--! 2012-03-10 - New index      EDIShipmentMaster

--! 2012-03-08 - Change column  EDIXrefComPaths

--! 2012-02-15 - Change column  EDIShipmentUPSDtl

--! 	         New columns    EDIXRefCarrierSCAC

--! 2012-01-30 - New columns    EDIXRefAddress

--! 2012-01-18 - New table      EDIShipmentSplit

--!              New table      EDIShipmentSplitPk

--!              New column     EDIShipmentMaster



--! 2011-12-12 - New table      EDIShipmentUSPS

--! 2011-12-01 - New columns    EDIXRefAccounts

--! 2011-11-21 - New column     EDIMasterDocument

--! 2011-10-17 - New column     EDIXRefSCAC

--! 2011-10-06 - New table      EDINext

--! 2011-08-28 - New column     EDIXRefCharges

--!              New column     EDIShipmentOrder

--!              New column     EDIXRefSCAC

--! 2011-08-07 - New column     EDIMasterDocument

--!              New column     EDIXRefAllowance

--! 2011-07-18 - New table      EDIBOTrackDetail

--!              New table      EDIBOTrackMaster

--!              New columns    EDIXRefDiscount

--! 2011-06-21 - New column     EDIShipmentPack

--! 2011-05-23 - New columns    EDILabelPackage

--! 2011-05-11 - New table      EDIShipmentFedex

--!              New columns    EDILabelPackage

--!              New column     EDIXrefQuestions

--! 2011-04-29 - New column     EDIShipmentPack

--! 2011-04-04 - New column     EDILabelMaster

--!              New columns    EDIShipmentPack

--! 2011-03-28   New column     EDIDocsToProcess...Sort

--!              Change index   EDIDocsToProcess

--! 2011-03-14 - New columns    EDIXRefCharges

--! 2011-02-24 - New columns    EDIXRefDateTime

--! 2011-02-04 - New index      EDIShipmentMaster

--!              New column     EDIXRefAllowance

--! 2011-01-28 - New columns    EDIXRefDiscount



--! 2010-12-19 - New columns    EDIShipmentTare

--!              New columns    EDIShipmentItem

--!              New columns    EDIXRefUPC

--! 2010-11-30 - New column     EDIMasterDocument

--! 2010-10-18 - New column     EDIXRefReference

--! 2010-08-29 - New columns    EDIXRefDiscount

--! 2010-08-27 - New columns    EDIShipmentItem

--!              New columns    EDIShipmentOrder

--!              New columns    EDIShipmentPack

--!              New columns    EDIShipmentTare

--!              New columns    EDIXrefQuestions

--! 2010-07-19 - New columns    EDIXRefAddress

--! 2010-07-13 - New columns    EDIXRefComPaths 

--!              New column     EDIDocsToProcess...Sequence

--!              New index      EDIDocsToProcess

--! 2010-07-06 - New column     EDIXRefProduct

--! 2010-06-19 - New columns    EDIXRefSegmentRpt

--! 2010-05-26 - New columns    EDILabelPackage

--!              New columns    EDIShipmentUPSDtl

--!              New columns    EDIXRefPKGInstruct

--! 2010-05-22   New columns    EDIXRefComPaths 

--! 2010-05-13 - New table      EDIShipmentSerials

--!              New column     EDIXRefSCAC

--! 2010-05-12 - New columns    EDIShipmentMaster

--! 2010-05-06 - Change table   EDIAcknowledgement

--!              Change table   EDIArchive

--!              New table      EDIPreferences

--!              New columns    EDIXRefComPaths 

--! 2010-03-02 - New table      EDIXRefFrghtItem

--! 2010-03-02 - New column     EDIShipmentMaster..NMFCClass

--! 2010-02-24 - New columns    EDIXRefAddress

--! 2010-02-22 - New column     EDIXRefLabel...UCCOverride

--! 2010-01-28 - Add columns    EDIShipmentLock

--! 2010-01-13 - Add columns    EDIXRefWhseTrans



--! 2009-12-31 - New columns    EDILabelPackage

--!              New columns    EDIShipmentUPSBook

--!              New column     EDIShipmentUPSDtl...Country

--! 2008-12-04 - New column     EDIShipmentUPSDtl...InsurancePayor

--! 2009-11-18 - New columns    EDIMasterDocument

--! 2009-11-16 - New column     EDIShipmentMaster..ImportHandheld

--! 2009-10-23 - New columns    EDIXRefReference

--! 2009-10-12 - New columns    EDIXRefDiscount

--!              New columns    EDIXRefProduct

--! 2009-09-29 - New columns    EDIXRefCharges

--! 2009-09-15 - New column     EDIXRefComPaths 

--! 2009-08-23 - New column     EDIXRefSegmentRpt..Required

--! 2009-08-21 - New columns    EDIXRefLabel 

--! 2009-07-31 - New column     EDILabelMaster..ShipDate

--! 2009-07-29 - New column     EDILabelDetail..Serial

--! 2009-07-21 - New columns    EDIMasterDocument

--!              New columns    EDIXRefUOM

--! 2009-07-20 - New columns    EDIPaymentMaster

--!              New table      EDIXRefSegmentRpt

--! 2009-07-08 - New column     EDIShipmentMaster..Volume

--! 2009-07-06 - Modify         EDILabelComments

--!              Modify         EDIPaymentComments

--!              Modify         EDIPaymentStockDet

--! 2009-06-26 - New columns    EDIXRefUOM

--! 2009-04-21 - New columns    EDIXRefAccounts

--!              New table      EDIXRefDangerous

--! 2009-04-17 - New index      EDIXRefStockSubIdxSub

--! 2009-03-12 - Increase Column Size EDIMasterInfo...RecordInfo

--! 2009-01-18 - New column     EDIPaymentDetail...GroupCustomer

--! 2009-01-17 - New columns    EDIXRefDateTime

--!              New columns    EDIXRefProduct

--!              New columns    EDIXRefReference

--! 2009-01-14 - Rename columns EDIControl

--!              New column and index EDIPaymentDetail...UnappliedGroup

--! 2009-01-13 - New column     EDIPaymentDetail...OriginalDiscount

--! 2009-01-06 - New column     EDIUPSSurcharges...Extended



--! 2008-12-19 - New column     EDIDocsToProcess...EDIDocument

--! 2008-12-18 - New column     EDIXRefAddress...RemoveModifier

--! 2008-12-17 - New columns    EDIXRefReference

--! 2008-12-15 - New columns    EDIXRefCharges

--!              New columns    EDIXRefSCAC

--! 2008-02-13 - New columns    EDIShipmentOrder

--! 2008-12-11 - Drop table     EDIXRefHandhelds

--!              Drop table     EDIMasterStation

--! 2008-12-10 - Correct table name EDIXRefPromotions

--!              New table      EDIXRefFrghtClass

--!              Drop table     EDIXRefFreightClas

--! 2008-12-04 - New columns    EDIXRefLocation

--!              New column     EDIXRefCarrierInfo...EffectiveDate

--! 2008-11-28 - New column     EDIXRefDiscount...IgnoreMOH

--! 2008-11-24 - New Index      EDILabelMasterIdxShipment

--! 2008-11-12 - New column     EDIXRefAddress...SCTFlag

--! 2008-10-01 - New column     EDIXRefAddress...Cta0201

--! 2008-09-30 - Modify         EDIChanges

--! 2008-09-19 - New column     EDIShipmentMaster..LastStation

--! 2008-09-18 - New columns    EDIXRefUPC

--! 2008-08-26 - New column     EDIXRefAddress

--!              New columns    EDIMasterPartner

--! 2008-08-25 - New columns    EDIShipmentUPSDtl

--!              New column     EDIXRefDimensions

--!              New columns    EDIXRefSCAC

--!              New column     EDIXRefServices

--! 2008-06-02 - Expand ShippingDays in EDIXRefDateTime

--! 2008-05-28 - New column     EDIXRefSCAC

--! 2008-05-15 - New columns    EDIXRefWhseTrans 

--! 2008-05-14 - New table      EDIXRefWhseTrans

--! 2008-05-01 - New columns    EDIXRefLabel 

--!              New column     EDIShipmentLock 

--! 2008-04-21 - New columns    EDIXRefComPaths 

--! 2008-04-11 - New columns    EDIXRefAllowance

--! 2008-03-30 - New columns    EDIXRefReference

--! 2008-03-13 - Change column  EDIXRefEMailRoutes

--! 2008-03-11 - New columns    EDIShipmentUPSDtl

--! 2008-02-29 - New column     EDIReceiverMaster..Unit

--!              New column     EDIShipmentMaster..Unit

--!              New column     EDITakeMaster..Unit

--! 2008-02-04 - New table      EDIMasterStations

--!              New column     EDIXRefPrinters..Method

--! 2008-01-26 - New column     EDIXRefEmployees

--!              Drop old columns EDIXRefEmployee

--!              New table      EDIMasterHandhelds



--! 2007-12-27 - New columns    EDIControl

--! 2007-10-18 - New columns    EDIXRefAccounts

--! 2007-09-06 - New columns    EDIXRefAccounts

--!              Change Key Fields in EDIXRefCarrierInfo

--! 2007-06-16 - New columns    EDIMasterPartner

--! 2007-05-17 - New column     EDIXRefProduct..LeaveBlank 

--! 2007-04-06 - New column     EDIShipmentPack

--! 2007-03-06 - New columns    EDIXRefComPaths 

--!              New columns    EDIShipmentMaster



PRINT 'SQL Script to update Cadacus, Inc. - Solutions for SYSPRO tables starting'

PRINT ' '

PRINT 'Note :  Any messages starting with ##### ERROR #####'

PRINT '        should be reported to your support organization for analysis'

PRINT ' '

GO



--! Add function to test for indexes



IF OBJECT_ID('dbo.CadacusIndexTest') IS NOT NULL

   DROP FUNCTION  dbo.CadacusIndexTest

GO



CREATE FUNCTION dbo.CadacusIndexTest(@idx nvarchar(50)) RETURNS INT

AS

BEGIN

  DECLARE @Exists INT

  SET @Exists=0

  IF (SELECT SERVERPROPERTY('productversion')) > '9'

   BEGIN

    IF (SELECT COUNT(*) FROM sys.indexes WHERE name=@idx) = 1

      SET @Exists=1

   END

  ELSE

   BEGIN

    IF (SELECT COUNT(*) FROM sysindexes WHERE name=@idx) = 1

      SET @Exists=1

   END

  RETURN @Exists

END

GO



--! Add function to test column lengths



IF OBJECT_ID('dbo.CadacusColumnTest') IS NOT NULL

   DROP FUNCTION  dbo.CadacusColumnTest

GO



CREATE FUNCTION dbo.CadacusColumnTest(@table nvarchar(50), @column nvarchar(50), @length int) RETURNS INT

AS

BEGIN



  DECLARE @Correct INT

  SET @Correct=0



  IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME=@table and COLUMN_NAME=@column and CHARACTER_MAXIMUM_LENGTH=@length) = 1

	BEGIN

      SET @Correct=1

    END



  RETURN @Correct

END

GO



--! Setup temporary change database



IF OBJECT_ID('tempdb..#CadacusNewColumns') IS NOT NULL

   DROP Table  #CadacusNewColumns

GO   



CREATE TABLE #CadacusNewColumns (

	[ColumnType] [varchar](1),

	[ColumnTable] [varchar](100),

	[ColumnName] [varchar](100) )

GO



--! Setup Procedures



IF OBJECT_ID('dbo.CadacusError') IS NOT NULL

   DROP PROCEDURE dbo.CadacusError

GO



CREATE PROCEDURE dbo.CadacusError(@msg nvarchar(500))

AS

BEGIN

  PRINT ' '

  PRINT '############### ERROR ##############'

  PRINT 'Error ' + LOWER(SUBSTRING(@msg,1,1)) + SUBSTRING(@msg,2,499)

  PRINT ERROR_MESSAGE()

  PRINT '############### ERROR ##############'

  PRINT ' '

END

GO



IF OBJECT_ID('dbo.CadacusNewColumnA') IS NOT NULL

   DROP PROCEDURE dbo.CadacusNewColumnA

GO



CREATE PROCEDURE dbo.CadacusNewColumnA(@cdate char(10), @ctype char(1), @ctable nvarchar(50), @cname nvarchar(50), @length int, @decimals int, @cnull nvarchar(10), @setdefault char(1))

AS

BEGIN

  IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

	    WHERE TABLE_NAME=@ctable AND COLUMN_NAME=@cname) = 0

  BEGIN

    DECLARE @msg     nvarchar(500)

    DECLARE @default nvarchar(50)

    

    SET @msg = 'New column ' + @ctable + '..' + @cname + '  (' + @cdate + ')'

    BEGIN TRY

      PRINT @msg



      SET @default = ''

      IF @cnull='NOT'

        BEGIN

          SET @default = ' DEFAULT '' '''

        END



      IF @ctype='C'

        BEGIN

          EXEC ('ALTER TABLE ' + @ctable + ' ADD ' + @cname+ ' CHAR(' + @length + ') ' + @cnull + ' NULL' + @default)

        END

      IF @ctype='D'

        BEGIN

          EXEC ('ALTER TABLE ' + @ctable + ' ADD ' + @cname+ ' DATETIME ' + @cnull + ' NULL')

        END

      IF @ctype='N'

        BEGIN

          EXEC ('ALTER TABLE ' + @ctable + ' ADD ' + @cname+ ' DECIMAL(' + @length + ',' + @decimals + ') ' + @cnull + ' NULL')

        END



      IF @setdefault='Y'

        BEGIN

          SET NOCOUNT ON

          INSERT INTO #CadacusNewColumns (ColumnType,ColumnTable, ColumnName) VALUES (@ctype ,  @ctable , @cname )

          SET NOCOUNT OFF

        END

        

    END TRY

    BEGIN CATCH

      EXEC dbo.CadacusError @msg

    END CATCH

  END

END

GO



IF OBJECT_ID('dbo.CadacusNewColumn') IS NOT NULL

   DROP PROCEDURE dbo.CadacusNewColumn

GO



CREATE PROCEDURE dbo.CadacusNewColumn(@cdate char(10), @ctype char(1), @ctable nvarchar(50), @cname nvarchar(50), @length int, @decimals int) 

AS

BEGIN

  EXEC dbo.CadacusNewColumnA @cdate, @ctype, @ctable, @cname, @length, @decimals, '', 'Y'

END

GO



IF OBJECT_ID('dbo.CadacusNewColumnNotNull') IS NOT NULL

   DROP PROCEDURE dbo.CadacusNewColumnNotNull

GO



CREATE PROCEDURE dbo.CadacusNewColumnNotNull(@cdate char(10), @ctype char(1), @ctable nvarchar(50), @cname nvarchar(50), @length int, @decimals int) 

AS

BEGIN

  EXEC dbo.CadacusNewColumnA @cdate, @ctype, @ctable, @cname, @length, @decimals, 'NOT', 'Y'

END

GO



IF OBJECT_ID('dbo.CadacusNewColumnNoDefault') IS NOT NULL

   DROP PROCEDURE dbo.CadacusNewColumnNoDefault

GO



CREATE PROCEDURE dbo.CadacusNewColumnNoDefault(@cdate char(10), @ctype char(1), @ctable nvarchar(50), @cname nvarchar(50), @length int, @decimals int) 

AS

BEGIN

  EXEC dbo.CadacusNewColumnA @cdate, @ctype, @ctable, @cname, @length, @decimals, '', 'N'

END

GO



IF OBJECT_ID('dbo.CadacusAlterColumn') IS NOT NULL

   DROP PROCEDURE dbo.CadacusAlterColumn

GO



CREATE PROCEDURE dbo.CadacusAlterColumn(@cdate char(10), @ctype char(1), @ctable nvarchar(50), @cname nvarchar(50), @length int, @decimals int) 

AS

BEGIN

  BEGIN TRY

    DECLARE @msg nvarchar(500)

    SET @msg = 'Changed column ' + @ctable + '..' + @cname + '  (' + @cdate + ')'



    IF (SELECT COUNT(*) FROM sysobjects WHERE ((xtype='D') and (name='Syspro_DF_' + @ctable + '_' + @cname))) = 1

      BEGIN

        EXEC ('ALTER TABLE ' + @ctable + ' DROP CONSTRAINT ' + 'Syspro_DF_' + @ctable + '_' + @cname)

      END



    DECLARE @NULLABLE CHAR(10)

    SET @NULLABLE = 'NULL'

    IF (SELECT IS_NULLABLE from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=@ctable AND COLUMN_NAME=@cname) = 'NO'

      BEGIN

        SET @NULLABLE = ' NOT NULL'

      END

  

    IF @ctype='C'

      BEGIN

        IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=@ctable AND COLUMN_NAME=@cname AND CHARACTER_MAXIMUM_LENGTH=@length) = 0

          BEGIN 

            PRINT @msg

            EXEC ('ALTER TABLE ' + @ctable + ' ALTER COLUMN ' + @cname+ ' CHAR(' + @length + ')' + @NULLABLE)

          END

      END



    IF @ctype='N'

      BEGIN

        IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=@ctable AND COLUMN_NAME=@cname AND NUMERIC_PRECISION=@length AND NUMERIC_SCALE=@decimals) = 0

          BEGIN

           PRINT @msg

           EXEC ('ALTER TABLE ' + @ctable + ' ALTER COLUMN ' + @cname+ ' DECIMAL(' + @length + ',' + @decimals + ')' + @NULLABLE)

          END

      END

  END TRY

  BEGIN CATCH

    EXEC dbo.CadacusError @msg

  END CATCH

END

GO





IF OBJECT_ID('dbo.CadacusDropPrimaryKey') IS NOT NULL

  DROP PROCEDURE dbo.CadacusDropPrimaryKey

GO



CREATE PROCEDURE dbo.CadacusDropPrimaryKey(@ctable nvarchar(50), @cname nvarchar(50), @length int)

AS

BEGIN

  DECLARE @msg nvarchar(500)

  SET @msg = 'Temporarily dropping primary key ' + @ctable + '..' + @ctable + 'Key'

  BEGIN TRY

    IF (dbo.CadacusIndexTest(@ctable + 'Key') = 1)

      BEGIN

        IF (dbo.CadacusColumnTest(@ctable,@cname,@length) = 0)

          BEGIN

            PRINT 'Temporarily dropping primary key ' + @ctable + '..' + @ctable + 'Key'

            EXEC ('ALTER TABLE ' + @ctable + ' DROP CONSTRAINT ' + @ctable+ 'Key')

          END

      END

  END TRY

  BEGIN CATCH

    EXEC dbo.CadacusError @msg

  END CATCH

END

GO



IF OBJECT_ID('dbo.CadacusAddPrimaryKey') IS NOT NULL

  DROP PROCEDURE dbo.CadacusAddPrimaryKey

GO



CREATE PROCEDURE dbo.CadacusAddPrimaryKey(@ctable nvarchar(50), @columns nvarchar(200))

AS

BEGIN

  DECLARE @msg nvarchar(500)

  SET @msg = 'Adding primary key ' + @ctable + '..' + @ctable + 'Key'

  BEGIN TRY

    IF (dbo.CadacusIndexTest(@ctable + 'Key') = 0)

      BEGIN

        PRINT @msg

        EXEC ('ALTER TABLE ' + @ctable + ' ADD CONSTRAINT ' + @ctable+ 'Key PRIMARY KEY CLUSTERED ( ' + @columns + ' ) ')

      END

  END TRY

  BEGIN CATCH

    EXEC dbo.CadacusError @msg

  END CATCH

END

GO



IF OBJECT_ID('dbo.CadacusDropIndex') IS NOT NULL

  DROP PROCEDURE dbo.CadacusDropIndex

GO



CREATE PROCEDURE dbo.CadacusDropIndex(@ctable nvarchar(50), @cidx nvarchar(20), @cname nvarchar(50), @length int)

AS

BEGIN

  DECLARE @msg nvarchar(500)

  SET @msg = 'Temporarily dropping index ' + @ctable + '..' + @ctable + 'Idx' + @cidx

  BEGIN TRY

    IF (dbo.CadacusColumnTest(@ctable,@cname,@length) = 0)

      BEGIN

        IF (dbo.CadacusIndexTest(@ctable + 'Idx' + @cidx) = 1)

          BEGIN

            PRINT @msg

            EXEC ('DROP INDEX ' + @ctable + '.' + @ctable+ 'Idx' + @cidx)

          END

      END

  END TRY

  BEGIN CATCH

    EXEC dbo.CadacusError @msg

  END CATCH

END

GO



IF OBJECT_ID('dbo.CadacusAddIndex') IS NOT NULL

  DROP PROCEDURE dbo.CadacusAddIndex

GO



CREATE PROCEDURE dbo.CadacusAddIndex(@ctable nvarchar(50), @cidx nvarchar(20), @columns nvarchar(200))

AS

BEGIN

  DECLARE @msg nvarchar(500)

  SET @msg = 'Adding index ' + @ctable + '..' + @ctable + 'Idx' + @cidx

  BEGIN TRY

    IF (dbo.CadacusIndexTest(@ctable + 'Idx' + @cidx) = 0)

      BEGIN

        PRINT @msg

        EXEC ( 'CREATE UNIQUE INDEX ' + @ctable+ 'Idx' + @cidx + ' ON ' + @ctable + ' ( ' + @columns + ' )')

      END

  END TRY

  BEGIN CATCH

    EXEC dbo.CadacusError @msg

  END CATCH

END

GO



IF OBJECT_ID('dbo.CadacusRenameColumn') IS NOT NULL

  DROP PROCEDURE dbo.CadacusRenameColumn

GO



CREATE PROCEDURE dbo.CadacusRenameColumn(@cdate char(10), @ctable nvarchar(50), @cold nvarchar(50), @cnew nvarchar(50), @addcomputed varchar(1))

AS

BEGIN

  DECLARE @oldColumn nvarchar(50)

  SET @oldColumn = @ctable + '.' + @cold

  

  DECLARE @msg nvarchar(500)

  SET @msg = 'Renaming column ' + @oldColumn + ' to ' + @cnew + ' (' + @cdate + ') - Please ignore "Caution" message'



  DECLARE @msg2 nvarchar(500)

  SET @msg2 = '  Adding computed column '  + @ctable + '..' + @oldColumn + ' equal to ' + @cnew + ' for compatibility '

  

  BEGIN TRY

    IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=@ctable AND COLUMN_NAME=@cold) = 1

      BEGIN

        PRINT @msg

        EXEC sp_rename @oldColumn, @cnew, 'COLUMN'

        IF @addcomputed='Y'

          BEGIN

            PRINT @msg2

            EXEC ('ALTER TABLE ' + @ctable + ' ADD [' + @cold + '] AS ([' + @cnew + '])')

          END

      END

  END TRY

  BEGIN CATCH

    EXEC dbo.CadacusError @msg

  END CATCH

END

GO



IF OBJECT_ID('dbo.CadacusDropColumn') IS NOT NULL

  DROP PROCEDURE dbo.CadacusDropColumn

GO



CREATE PROCEDURE dbo.CadacusDropColumn(@cdate char(10), @ctable nvarchar(50), @cold nvarchar(50))

AS

BEGIN

  DECLARE @oldColumn nvarchar(50)

  SET @oldColumn = @ctable + '.' + @cold

  

  DECLARE @msg nvarchar(500)

  SET @msg = 'Dropping column ' + @oldColumn + ' (' + @cdate + ')'



  BEGIN TRY

    IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=@ctable AND COLUMN_NAME=@cold) = 1

      BEGIN

        PRINT @msg

        EXEC ('ALTER TABLE ' + @ctable + ' DROP COLUMN [' + @cold + ']')

      END

  END TRY

  BEGIN CATCH

    EXEC dbo.CadacusError @msg

  END CATCH

END

GO



IF OBJECT_ID('dbo.CadacusDropTable') IS NOT NULL

  DROP PROCEDURE dbo.CadacusDropTable

GO



CREATE PROCEDURE dbo.CadacusDropTable(@cdate char(10), @ctable nvarchar(50))

AS

BEGIN

  DECLARE @msg nvarchar(500)

  SET @msg = 'Dropping table  ' + @ctable + ' (' + @cdate + ')'



  BEGIN TRY

    IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME=@ctable) = 1

    BEGIN

      PRINT @msg

      EXEC ( 'DROP TABLE ' + @ctable )

    END

  END TRY

  BEGIN CATCH

    EXEC dbo.CadacusError @msg

  END CATCH

END

GO



--! Start database changes



PRINT 'Checking table EDIAcknowledgement'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIAcknowledgment' AND COLUMN_NAME='GSControl') = 1

BEGIN

  ALTER TABLE EDIAcknowledgment DROP CONSTRAINT EDIAcknowledgmentKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIAcknowledgment' AND COLUMN_NAME='GSControl') = 1

 BEGIN

    EXEC sp_rename 'EDIAcknowledgment.GSControl',      'GrpControl',      'COLUMN';

    EXEC sp_rename 'EDIAcknowledgment.STControl',      'DocControl',      'COLUMN';

    EXEC sp_rename 'EDIAcknowledgment.ISAControl',     'EnvControl',      'COLUMN';

    ALTER TABLE EDIAcknowledgment  ADD

       DocDate                  DATETIME            NULL,

       DocTime                  DECIMAL(8,0)        NULL,

       ACKDate                  DATETIME            NULL,

       ACKTime                  DECIMAL(8,0)        NULL,

       ReverseDate              DECIMAL(9,0)        NULL,

       ReverseTime              DECIMAL(8,0)        NULL

    PRINT 'Convert table EDIAcknowledgment - Part 1 (05/06/2010)'

 END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIAcknowledgment' AND COLUMN_NAME='OrgDateTime') = 1

 BEGIN

    DECLARE @UPD NCHAR(500)

    SET @UPD=N'    UPDATE EDIAcknowledgment SET

    	DocDate=LEFT([OrgDateTime],8),

        DocTime=(RIGHT([OrgDateTime],4) * 10000),

    	ACKDate=LEFT([ACKDateTime],8),

        ACKTime=(RIGHT([ACKDateTime],4) * 10000),

        ReverseDate=(999999999 - LEFT([OrgDateTime],8)),

        ReverseTime=(99999999 - (RIGHT([OrgDateTime],4) * 10000))'



    EXEC sp_executesql @UPD



    ALTER TABLE EDIAcknowledgment DROP COLUMN OrgDateTime

    

    ALTER TABLE EDIAcknowledgment DROP COLUMN ACKDateTime

    

    ALTER TABLE EDIAcknowledgment ADD CONSTRAINT EDIAcknowledgmentKey PRIMARY KEY CLUSTERED

         (

          Partner,

          Direction,

          Type,

          GrpControl,

          DocControl

         )

    

    CREATE UNIQUE INDEX EDIAcknowledgmentIdxDate ON EDIAcknowledgment(

     DocDate,

     DocTime,

     Partner,

     Direction,

     Type,

     GrpControl,

     DocControl

     )

     

    CREATE UNIQUE INDEX EDIAcknowledgmentIdxReverse ON EDIAcknowledgment(

     ReverseDate,

     ReverseTime,

     Partner,

     Direction,

     Type,

     GrpControl,

     DocControl

     )

    PRINT 'Convert table EDIAcknowledgment - Part 2 (05/06/2010)'

 END

GO





PRINT 'Checking table EDIAOMAvailable'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIAOMAvailable') = 0

BEGIN

    CREATE TABLE EDIAOMAvailable(

     StockCode                CHAR(30)            NOT NULL,

     Warehouse                CHAR(10)            NOT NULL,

     Available                DECIMAL(18,6)       NULL,

     Remaining                DECIMAL(18,6)       NULL,

     RemainingOnHand          DECIMAL(18,6)       NULL,

     Bin                      CHAR(20)            NULL,

     WhseAvailable            DECIMAL(18,6)       NULL,

     BinHold                  DECIMAL(18,6)       NULL,

     LotHold                  DECIMAL(18,6)       NULL,

     OnHand                   DECIMAL(18,6)       NULL,

     ShipQty                  DECIMAL(18,6)       NULL,

     Status                   CHAR(1)             NULL,

     Decimals                 DECIMAL(1,0)        NULL,

     AlternateUom             CHAR(10)            NULL,

     OtherUom                 CHAR(10)            NULL,

     ConvFactAltUom           DECIMAL(12,6)       NULL,

     ConvMulDiv               CHAR(1)             NULL,

     ConvFactOthUom           DECIMAL(12,6)       NULL,

     MulDiv                   CHAR(1)             NULL,

     LotDate                  DATETIME            NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIAOMAvailableKey PRIMARY KEY CLUSTERED

         (

          StockCode,

          Warehouse

         )

    )

    CREATE UNIQUE INDEX EDIAOMAvailableIdxStatus ON EDIAOMAvailable(

     Status,

     StockCode,

     Warehouse

     )

    PRINT 'New table EDIAOMAvailable (11/02/2016)'

END

GO



EXEC dbo.CadacusNewColumn        '03/21/2021','N','EDIAOMAvailable','StatusHold',18,6

EXEC dbo.CadacusNewColumn        '05/26/2021','C','EDIAOMAvailable','Exclusion',1,0

EXEC dbo.CadacusNewColumn        '09/23/2021','N','EDIAOMAvailable','LotExpired',18,6

EXEC dbo.CadacusNewColumn        '09/23/2021','N','EDIAOMAvailable','QtyAllocatedWip',18,6

EXEC dbo.CadacusNewColumn        '09/23/2021','N','EDIAOMAvailable','WhseOnHand',18,6

EXEC dbo.CadacusNewColumn        '09/23/2021','N','EDIAOMAvailable','ToShip',18,6



PRINT 'Checking table EDIAOMDetail'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIAOMDetail') = 0

BEGIN

    CREATE TABLE EDIAOMDetail(

     AOMShipDate              DATETIME            NOT NULL,

     SalesOrder               CHAR(20)            NOT NULL,

     LineNumber               DECIMAL(4,0)        NOT NULL,

     OrderQuantity            DECIMAL(18,6)       NULL,

     ShipQuantity             DECIMAL(18,6)       NULL,

     BOQuantity               DECIMAL(18,6)       NULL,

     AllocQuantity            DECIMAL(18,6)       NULL,

     AllocStockQty            DECIMAL(18,6)       NULL,

     OrderUOM                 CHAR(10)            NULL,

     StockingUOM              CHAR(10)            NULL,

     StockCode                CHAR(30)            NULL,

     Warehouse                CHAR(10)            NULL,

     Status                   CHAR(1)             NULL,

     Force                    DECIMAL(18,6)       NULL,

     ConvFactAlloc            DECIMAL(12,6)       NULL,

     MulDivQtyFct             CHAR(1)             NULL,

     ProductClass             CHAR(20)            NULL,

     LineShipDate             DATETIME            NULL,

     KitParent                DECIMAL(4,0)        NULL,

     TraceableType            CHAR(1)             NULL,

     SubStockCode             CHAR(30)            NULL,

     SubOrgQty                DECIMAL(18,6)       NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIAOMDetailKey PRIMARY KEY CLUSTERED

         (

          AOMShipDate,

          SalesOrder,

          LineNumber

         )

    )

    CREATE UNIQUE INDEX EDIAOMDetailIdxOrd ON EDIAOMDetail(

     SalesOrder,

     LineNumber

     )

    CREATE UNIQUE INDEX EDIAOMDetailIdxStk ON EDIAOMDetail(

     StockCode,

     Warehouse,

     SalesOrder,

     LineNumber

     )

    CREATE UNIQUE INDEX EDIAOMDetailIdxPcl ON EDIAOMDetail(

     ProductClass,

     Warehouse,

     SalesOrder,

     LineNumber

     )

    CREATE UNIQUE INDEX EDIAOMDetailIdxDat ON EDIAOMDetail(

     StockCode,

     Warehouse,

     AOMShipDate,

     SalesOrder,

     LineNumber

     )

    CREATE UNIQUE INDEX EDIAOMDetailIdxWh ON EDIAOMDetail(

     Warehouse,

     SalesOrder,

     LineNumber

     )

    PRINT 'New table EDIAOMDetail'

END

GO



EXEC dbo.CadacusNewColumn        '08/19/2018','N','EDIAOMDetail','ReservedQuantity',18,6

EXEC dbo.CadacusNewColumn        '05/26/2021','N','EDIAOMDetail','Shortage',18,6

EXEC dbo.CadacusNewColumn        '05/26/2021','C','EDIAOMDetail','Exclusion',1,0

EXEC dbo.CadacusNewColumn        '05/26/2021','N','EDIAOMDetail','FillPercentage',5,2

EXEC dbo.CadacusNewColumn        '05/26/2021','N','EDIAOMDetail','OrderValue',14,2

EXEC dbo.CadacusNewColumn        '05/26/2021','N','EDIAOMDetail','FillValue',14,2

EXEC dbo.CadacusNewColumn        '05/26/2021','N','EDIAOMDetail','OpenValue',14,2

EXEC dbo.CadacusNewColumn        '05/26/2021','N','EDIAOMDetail','AltAllocQty',18,6

EXEC dbo.CadacusNewColumn        '05/26/2021','N','EDIAOMDetail','AltAllocStkQty',18,6

EXEC dbo.CadacusNewColumn        '05/26/2021','N','EDIAOMDetail','AltFillPercentage',5,2

EXEC dbo.CadacusNewColumn        '05/26/2021','N','EDIAOMDetail','AltFillValue',14,2

EXEC dbo.CadacusNewColumn        '04/18/2022','N','EDIAOMDetail','AltShortage',18,6



PRINT 'Checking table EDIAOMLocks'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIAOMLocks') = 0

BEGIN

    CREATE TABLE EDIAOMLocks(

     Control                  CHAR(2)             NOT NULL,

     Warehouse                CHAR(10)            NOT NULL,

     Operator                 CHAR(20)            NOT NULL,

     Program                  CHAR(6)             NULL,

     OperatorName             CHAR(30)            NULL,

     DateOfLock               DATETIME            NULL,

     TimeOfLock               DECIMAL(8,0)        NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIAOMLocksKey PRIMARY KEY CLUSTERED

         (

          Control,

          Warehouse,

          Operator

         )

    )

    PRINT 'New table EDIAOMLocks'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIAOMLocks' AND COLUMN_NAME='Bin') = 0

BEGIN

    ALTER TABLE EDIAOMLocks ADD

     Bin                CHAR(20)            NULL

    PRINT 'New column EDIAOMLocks (05/09/2016)'

END

GO



PRINT 'Checking table EDIAOMMaster'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIAOMMaster') = 0

BEGIN

    CREATE TABLE EDIAOMMaster(

     KeyWarehouse             CHAR(10)            NOT NULL,

     AOMDate                  DATETIME            NOT NULL,

     FillPercentage           DECIMAL(5,2)        NOT NULL,

     CustomerRank             CHAR(10)            NOT NULL,

     OrderRank                CHAR(10)            NOT NULL,

     SalesOrder               CHAR(20)            NOT NULL,

     Customer                 CHAR(15)            NULL,

     MasterCustomer           CHAR(15)            NULL,

     CustomerName             CHAR(50)            NULL,

     Warehouse                CHAR(10)            NULL,

     Weight                   DECIMAL(7,0)        NULL,

     OrderValue               DECIMAL(14,2)       NULL,

     FillValue                DECIMAL(14,2)       NULL,

     Zip                      CHAR(10)            NULL,

     OrderType                CHAR(2)             NULL,

     SCTOrder                 CHAR(1)             NULL,

     SessionOper              CHAR(20)            NULL,

     SessionTime              DECIMAL(8,0)        NULL,

     Status                   CHAR(1)             NULL,

     Force                    CHAR(1)             NULL,

     ShipViaCode              CHAR(6)             NULL,

     ShipVia                  CHAR(50)            NULL,

     CustomerClass            CHAR(10)            NULL,

     Priority1                CHAR(1)             NULL,

     Priority2                CHAR(1)             NULL,

     Complete                 CHAR(1)             NULL,

     DeallocateFlag           CHAR(1)             NULL,

     Routing                  CHAR(1)             NULL,

     LineCount                DECIMAL(4,0)        NULL,

     ItemCount                DECIMAL(9,0)        NULL,

     OrderDate                DATETIME            NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIAOMMasterKey PRIMARY KEY CLUSTERED

         (

          KeyWarehouse,

          AOMDate,

          FillPercentage,

          CustomerRank,

          OrderRank,

          SalesOrder

         )

    )

    CREATE UNIQUE INDEX EDIAOMMasterIdxWhOrd ON EDIAOMMaster(

     KeyWarehouse,

     SalesOrder,

     AOMDate

     )

    CREATE UNIQUE INDEX EDIAOMMasterIdxStatus ON EDIAOMMaster(

     SessionOper,

     SessionTime,

     Status,

     KeyWarehouse,

     SalesOrder,

     AOMDate

     )

    CREATE UNIQUE INDEX EDIAOMMasterIdxOrd ON EDIAOMMaster(

     SalesOrder,

     KeyWarehouse,

     AOMDate

     )

    CREATE UNIQUE INDEX EDIAOMMasterIdxSort ON EDIAOMMaster(

     KeyWarehouse,

     Priority1,

     Priority2,

     AOMDate,

     FillPercentage,

     CustomerRank,

     OrderRank,

     SalesOrder

     )

    PRINT 'New table EDIAOMMaster'

END

GO





EXEC dbo.CadacusNewColumn        '05/09/2016','N','EDIAOMMaster','OpenValue',14,2

EXEC dbo.CadacusNewColumn        '05/09/2016','N','EDIAOMMaster','ValuePercentage',5,2

EXEC dbo.CadacusNewColumn        '10/03/2016','C','EDIAOMMaster','RouteCode',10,0

EXEC dbo.CadacusNewColumn        '05/26/2021','N','EDIAOMMaster','AltFillPercentage',5,2

EXEC dbo.CadacusNewColumn        '05/26/2021','N','EDIAOMMaster','AltValuePercentage',5,2

EXEC dbo.CadacusNewColumn        '04/25/2022','C','EDIAOMMaster','DoNotShipBeforeFlg',1,0

EXEC dbo.CadacusNewColumn        '04/25/2022','D','EDIAOMMaster','CustomerReqDate',0,0

EXEC dbo.CadacusNewColumn        '04/25/2022','D','EDIAOMMaster','PromiseDate',0,0

EXEC dbo.CadacusNewColumn        '04/25/2022','C','EDIAOMMaster','OrderStatus',1,0



PRINT 'Checking table EDIAOMSelection'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIAOMSelection') = 0

BEGIN

    CREATE TABLE EDIAOMSelection(

     Counter                  DECIMAL(10,0)       NOT NULL,

     AddFlag                  CHAR(1)             NULL,

     Document                 CHAR(20)            NULL,

     DocumentFlag             CHAR(1)             NULL,

     ShipDate                 DATETIME            NULL,

     Requested                CHAR(1)             NULL,

     Released                 CHAR(1)             NULL,

     Printed                  CHAR(1)             NULL,

     Customer                 CHAR(15)            NULL,

     CustomerName             CHAR(50)            NULL,

     ActionFlag               CHAR(1)             NULL,

     Warehouse                CHAR(10)            NULL,

     OrderType                CHAR(2)             NULL,

     OrderValue               DECIMAL(14,2)       NULL,

     FillValue                DECIMAL(14,2)       NULL,

     ReleaseDate              DATETIME            NULL,

     LineCount                DECIMAL(4,0)        NULL,

     ItemCount                DECIMAL(9,0)        NULL,

     OrderDate                DATETIME            NULL,

     ShipViaCode              CHAR(6)             NULL,

     ShipVia                  CHAR(34)            NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIAOMSelectionKey PRIMARY KEY CLUSTERED

         (

          Counter

         )

    )

    CREATE UNIQUE INDEX EDIAOMSelectionIdxAction ON EDIAOMSelection(

     ActionFlag,

     Counter

     )

    CREATE UNIQUE INDEX EDIAOMSelectionIdxDoc ON EDIAOMSelection(

     Document,

     Counter

     )

    CREATE UNIQUE INDEX EDIAOMSelectionIdxWh ON EDIAOMSelection(

     Warehouse,

     Counter

     )

    PRINT 'New table EDIAOMSelection'

END

GO



EXEC dbo.CadacusAlterColumn      '01/18/2022','C','EDIAOMSelection','ShipVia',50,0

EXEC dbo.CadacusNewColumn        '01/18/2022','C','EDIAOMSelection','Rank',20,0

EXEC dbo.CadacusNewColumn        '01/18/2022','N','EDIAOMSelection','Shipment',9,0

EXEC dbo.CadacusAddIndex         'EDIAOMSelection', 'Rank', 'Rank, Counter'



PRINT 'Checking table EDIAOMSecondary'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIAOMSecondary') = 0

BEGIN

    CREATE TABLE EDIAOMSecondary(

     Counter                  DECIMAL(10,0)       NOT NULL,

     Document                 CHAR(20)            NOT NULL,

     ShipDate                 DATETIME            NOT NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIAOMSecondaryKey PRIMARY KEY CLUSTERED

         (

          Counter,

          Document,

          ShipDate

         )

    )

    CREATE UNIQUE INDEX EDIAOMSecondaryIdxDoc ON EDIAOMSecondary(

     Document,

     Counter

     )

    PRINT 'New table EDIAOMSecondary'

END

GO





PRINT 'Checking table EDIAOMTransfers'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIAOMTransfers') = 0

BEGIN

    CREATE TABLE EDIAOMTransfers(

     Type                     CHAR(1)             NOT NULL,

     StockCode                CHAR(30)            NOT NULL,

     FromWarehouse            CHAR(10)            NOT NULL,

     ToWarehouse              CHAR(10)            NOT NULL,

     SalesOrder               CHAR(20)            NOT NULL,

     Quantity                 DECIMAL(18,6)       NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIAOMTransfersKey PRIMARY KEY CLUSTERED

         (

          Type,

          StockCode,

          FromWarehouse,

          ToWarehouse,

          SalesOrder

         )

    )

    CREATE UNIQUE INDEX EDIAOMTransfersIdxFromWh ON EDIAOMTransfers(

     Type,

     FromWarehouse,

     ToWarehouse,

     StockCode,

     SalesOrder

     )

    CREATE UNIQUE INDEX EDIAOMTransfersIdxToWh ON EDIAOMTransfers(

     Type,

     ToWarehouse,

     FromWarehouse,

     StockCode,

     SalesOrder

     )

    CREATE UNIQUE INDEX EDIAOMTransfersIdxOrder ON EDIAOMTransfers(

     Type,

     SalesOrder,

     StockCode,

     FromWarehouse,

     ToWarehouse

     )

    PRINT 'New table EDIAOMTransfers'

END

GO



PRINT 'Checking table EDIArchive'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIArchive' AND COLUMN_NAME='JulianDate') = 1

BEGIN

 IF (SELECT COUNT(*) FROM EDIArchive) > 0

 BEGIN

  CREATE TABLE EDIArchiveSave(

     [Partner]                  CHAR(10)            NOT NULL,

     [Document]                 CHAR(6)             NOT NULL,

     [Direction]                CHAR(1)             NOT NULL,

     [Type]                     CHAR(1)             NOT NULL,

     [DateTime]                 CHAR(14)            NOT NULL,

     [OriginalFile]             CHAR(100)           NULL,

     [ArchiveFile]              CHAR(100)           NULL,

     [Program]                  CHAR(6)             NULL,

     [Operator]                 CHAR(10)            NULL,

     [ID][int]                IDENTITY (1,1) NOT NULL)



  PRINT 'Setup table to save archive data (05/06/2010)'

 END

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIArchive' AND COLUMN_NAME='JulianDate') = 1

BEGIN

 IF (SELECT COUNT(*) FROM EDIArchive) > 0

 BEGIN

    DECLARE @UPD NCHAR(1000)

    SET @UPD=N'INSERT INTO EDIArchiveSave

    (Partner

     ,Document

     ,Direction

     ,Type

     ,DateTime

     ,OriginalFile

     ,ArchiveFile

     ,Program

      ,Operator)

  SELECT 

    Partner

     ,Document

     ,Direction

     ,Type

     ,DateTime

     ,OriginalFile

     ,ArchiveFile

     ,Program

     ,Operator

   FROM EDIArchive'



   EXEC sp_executesql @UPD

   PRINT 'Move archive data to save table and drop EDIArchive table (05/06/2010)'

 END

 DROP TABLE EDIArchive

 PRINT 'Drop old EDIArchive table (05/06/2010)'



END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIArchive') = 0

BEGIN

    CREATE TABLE EDIArchive(

     Partner                  CHAR(10)            NOT NULL,

     Document                 CHAR(10)            NOT NULL,

     Type                     CHAR(1)             NOT NULL,

     Code                     CHAR(1)             NOT NULL,

     SubCode                  CHAR(1)             NOT NULL,

     ArchiveDate              DATETIME            NOT NULL,

     ArchiveTime              DECIMAL(8,0)        NOT NULL,

     OriginalFile             CHAR(200)           NULL,

     ArchiveFile              CHAR(200)           NULL,

     Program                  CHAR(6)             NULL,

     Operator                 CHAR(10)            NULL,

     ReverseDate              DECIMAL(9,0)        NULL,

     ReverseTime              DECIMAL(8,0)        NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIArchiveKey PRIMARY KEY CLUSTERED

         (

          Partner,

          Document,

          Type,

          Code,

          SubCode,

          ArchiveDate,

          ArchiveTime

         )

    )

    CREATE UNIQUE INDEX EDIArchiveIdxArchive ON EDIArchive(

     ArchiveFile

     )

    CREATE UNIQUE INDEX EDIArchiveIdxDate ON EDIArchive(

     ArchiveDate,

     ArchiveTime,

     Partner,

     Document,

     Type,

     Code,

     SubCode

     )

    CREATE UNIQUE INDEX EDIArchiveIdxPartner ON EDIArchive(

     Partner,

     Document,

     ArchiveDate,

     ArchiveTime,

     Type,

     Code,

     SubCode

     )

    CREATE UNIQUE INDEX EDIArchiveIdxNewDate ON EDIArchive(

     ReverseDate,

     ReverseTime,

     Partner,

     Document,

     Type,

     Code,

     SubCode

     )

    CREATE UNIQUE INDEX EDIArchiveIdxNewPrtnr ON EDIArchive(

     Partner,

     Document,

     ReverseDate,

     ReverseTime,

     Type,

     Code,

     SubCode

     )



  PRINT 'Create new EDIArchive Table (05/06/2010)'

END     

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIArchiveSave') = 1

BEGIN

 IF ((SELECT COUNT(*) FROM EDIArchiveSave) > 0)

 BEGIN

  IF ((SELECT COUNT(*) FROM EDIArchive) = 0)

  BEGIN

   DECLARE @UPD NCHAR(1000)

   SET @UPD=N'INSERT INTO EDIArchive

    (Partner

     ,Document

     ,Type

     ,Code

     ,SubCode

     ,ArchiveDate

     ,ArchiveTime

     ,OriginalFile

     ,ArchiveFile

     ,Program

     ,Operator

     ,ReverseDate

     ,ReverseTime)

     SELECT 

      Partner

     ,Document

     ,Type

     ,Direction as Code

     ,'' '' as SubCode

     ,LEFT([DateTime],8) as ArchiveDate

     ,(RIGHT([DateTime],6) * 100) + (ID % 100) as ArchiveTime

     ,OriginalFile

     ,ArchiveFile

     ,Program

     ,Operator

     , 999999999 - LEFT([DateTime],8) as ReverseDate

     , 99999999 - ((RIGHT([DateTime],6) * 100) + (ID % 100)) as ReverseTime

     FROM EDIArchiveSave'



   EXEC sp_executesql @UPD



   UPDATE EDIArchive SET Document='          ' WHERE Document LIKE 'Combin' OR Document LIKE 'Sort'

   UPDATE EDIArchive SET Document='          ' WHERE Code='S' OR Code='C' OR Code='A' OR Code='U'

   UPDATE EDIArchive SET Code='S',SubCode='U' WHERE Code='U'

   UPDATE EDIArchive SET Type='X' WHERE OriginalFile LIKE '%.XML' OR OriginalFile LIKE '%.xml'

   UPDATE EDIArchive SET Code='H',Type='X' WHERE Type='S'

   UPDATE EDIArchive SET Code='T',Type='X' WHERE Type='T'

   UPDATE EDIArchive SET Code='R',Type='X' WHERE Type='C'

   UPDATE EDIArchive SET SubCode='E' WHERE OriginalFile LIKE '%Export%' AND Type='X'

   UPDATE EDIArchive SET SubCode='I' WHERE OriginalFile LIKE '%Import%' AND Type='X'

   UPDATE EDIArchive SET SubCode='S' WHERE OriginalFile LIKE '%Save%' AND Type='X'

   UPDATE EDIArchive SET Code='H' WHERE OriginalFile LIKE '%Shipment%' AND Type='X'

   UPDATE EDIArchive SET Code='T' WHERE OriginalFile LIKE '%Take%' AND Type='X'

   UPDATE EDIArchive SET Code='R' WHERE OriginalFile LIKE '%Receiver%' AND Type='X'



   PRINT 'Convert old archive data to new table (05/06/2010)'

  END

 END

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIArchiveSave') = 1

BEGIN

  PRINT ' '

  PRINT 'Table EDIArchiveSave may be DROPPED from SQL database after conversion is verified'

  PRINT 'if conversion is NOT successful, please contact SYSPRO support'

  PRINT ' '

END

GO



PRINT 'Checking table EDIBOTrackDetail'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIBOTrackDetail') = 0

BEGIN

    CREATE TABLE EDIBOTrackDetail(

     TransactionGUID          CHAR(36)            NOT NULL,

     Type                     CHAR(1)             NOT NULL,

     Counter                  DECIMAL(3,0)        NOT NULL,

     InfoLength               DECIMAL(4,0)        NULL,

     Information              CHAR(2900)          NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIBOTrackDetailKey PRIMARY KEY CLUSTERED

         (

          TransactionGUID,

          Type,

          Counter

         )

    )

    PRINT 'New table EDIBOTrackDetail'

END

GO



PRINT 'Checking table EDIBOTrackMaster'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIBOTrackMaster') = 0

BEGIN

    CREATE TABLE EDIBOTrackMaster(

     TransactionGUID          CHAR(36)            NOT NULL,

     Handheld                 CHAR(20)            NULL,

     Employee                 CHAR(6)             NULL,

     Object                   CHAR(6)             NULL,

     Class                    CHAR(1)             NULL,

     Method                   CHAR(1)             NULL,

     EntryDate                DATETIME            NULL,

     EntryTime                DECIMAL(8,0)        NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIBOTrackMasterKey PRIMARY KEY CLUSTERED

         (

          TransactionGUID

         )

    )

    CREATE UNIQUE INDEX EDIBOTrackMasterIdxDate ON EDIBOTrackMaster(

     EntryDate,

     EntryTime,

     TransactionGUID

     )

    CREATE UNIQUE INDEX EDIBOTrackMasterIdxHandheld ON EDIBOTrackMaster(

     Handheld,

     EntryDate,

     EntryTime,

     TransactionGUID

     )

    PRINT 'New table EDIBOTrackMaster'

END

GO



PRINT 'Checking table EDIControl'

GO



IF (SELECT COUNT(*) FROM EDIControl WHERE Control='CS') = 0

BEGIN

 IF (SELECT COUNT(*) FROM EDIControl WHERE Control='ED') = 1

  BEGIN

   IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

       WHERE TABLE_NAME='EDIControl' AND COLUMN_NAME='ADMReg') = 1

    BEGIN

       EXEC sp_rename 'EDIControl.ADMReg',      'AOMReg',      'COLUMN';

       EXEC sp_rename 'EDIControl.ADMRegYear',  'AOMRegYear',  'COLUMN';

       EXEC sp_rename 'EDIControl.ADMRegMonth', 'AOMRegMonth', 'COLUMN';

       PRINT 'Rename Fields in EDIControl (01/14/2009)'

    END

   ELSE

    BEGIN

     IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

       WHERE TABLE_NAME='EDIControl' AND COLUMN_NAME='AOMReg') = 0

     BEGIN

       ALTER TABLE EDIControl ADD AOMReg      decimal(10,0) NULL

       ALTER TABLE EDIControl ADD AOMRegYear  char(1) NULL

       ALTER TABLE EDIControl ADD AOMRegMonth char(1) NULL

       PRINT 'Add Registration Fields for AOM in EDIControl (12/27/2007)'

     END

    END

  END

END

GO



EXEC dbo.CadacusNewColumn '02/18/2018','C','EDIControl','Info',267,0



IF (SELECT COUNT(*) FROM EDIControl WHERE Control='CS') = 1

  BEGIN

   IF (SELECT COUNT(*) FROM EDIControl WHERE Control='ED') = 1

     BEGIN

       DELETE FROM EDIControl where Control='ED'

     END

   IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

     WHERE TABLE_NAME='EDIControl' AND COLUMN_NAME='DriveFlags') = 1

   BEGIN

    ALTER TABLE EDIControl DROP COLUMN DriveFlags

    ALTER TABLE EDIControl DROP COLUMN EDIReg

    ALTER TABLE EDIControl DROP COLUMN EDIRegYear

    ALTER TABLE EDIControl DROP COLUMN EDIRegMonth

    ALTER TABLE EDIControl DROP COLUMN Company

    ALTER TABLE EDIControl DROP COLUMN Users

    ALTER TABLE EDIControl DROP COLUMN ShipSystem

    ALTER TABLE EDIControl DROP COLUMN EDISystem

    ALTER TABLE EDIControl DROP COLUMN EDITRNVersion

    ALTER TABLE EDIControl DROP COLUMN ShipReg

    ALTER TABLE EDIControl DROP COLUMN IMPFILUpdate

    ALTER TABLE EDIControl DROP COLUMN IMPPRGUpdate

    ALTER TABLE EDIControl DROP COLUMN IMPMENUpdate

    ALTER TABLE EDIControl DROP COLUMN PalmReg

    ALTER TABLE EDIControl DROP COLUMN ReleaseReg

    ALTER TABLE EDIControl DROP COLUMN ShipRegYear

    ALTER TABLE EDIControl DROP COLUMN ShipRegMonth

    ALTER TABLE EDIControl DROP COLUMN PalmRegYear

    ALTER TABLE EDIControl DROP COLUMN PalmRegMonth

    ALTER TABLE EDIControl DROP COLUMN ReleaseRegYear

    ALTER TABLE EDIControl DROP COLUMN ReleaseRegMonth

    ALTER TABLE EDIControl DROP COLUMN SecurityFlag

    ALTER TABLE EDIControl DROP COLUMN SQLFlag

    ALTER TABLE EDIControl DROP COLUMN ImportReg

    ALTER TABLE EDIControl DROP COLUMN ImportRegYear

    ALTER TABLE EDIControl DROP COLUMN ImportRegMonth

    ALTER TABLE EDIControl DROP COLUMN FreightReg

    ALTER TABLE EDIControl DROP COLUMN FreightRegYear

    ALTER TABLE EDIControl DROP COLUMN FreightRegMonth

    ALTER TABLE EDIControl DROP COLUMN IMPTRRUpdate

    ALTER TABLE EDIControl DROP COLUMN CreatePOReg

    ALTER TABLE EDIControl DROP COLUMN CreatePORegYear

    ALTER TABLE EDIControl DROP COLUMN CreatePORegMonth

    ALTER TABLE EDIControl DROP COLUMN ConsolidateReg

    ALTER TABLE EDIControl DROP COLUMN ConsolidateRegYear

    ALTER TABLE EDIControl DROP COLUMN ConsolidateRegMth

    ALTER TABLE EDIControl DROP COLUMN RMACaptureReg

    ALTER TABLE EDIControl DROP COLUMN RMACaptureRegYear

    ALTER TABLE EDIControl DROP COLUMN RMACaptureRegMonth

    ALTER TABLE EDIControl DROP COLUMN VMIReg

    ALTER TABLE EDIControl DROP COLUMN VMIRegYear

    ALTER TABLE EDIControl DROP COLUMN VMIRegMonth

    ALTER TABLE EDIControl DROP COLUMN AFRReg

    ALTER TABLE EDIControl DROP COLUMN AFRRegYear

    ALTER TABLE EDIControl DROP COLUMN AFRRegMonth

    ALTER TABLE EDIControl DROP COLUMN RECReg

    ALTER TABLE EDIControl DROP COLUMN RECRegYear

    ALTER TABLE EDIControl DROP COLUMN RECRegMonth

    ALTER TABLE EDIControl DROP COLUMN TAKEReg

    ALTER TABLE EDIControl DROP COLUMN TAKERegYear

    ALTER TABLE EDIControl DROP COLUMN TAKERegMonth

    ALTER TABLE EDIControl DROP COLUMN DDSupdate

    PRINT 'Drop old fields in EDIControl (02/18/2018)'

   END

   IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

     WHERE TABLE_NAME='EDIControl' AND COLUMN_NAME='AOMReg') = 1

   BEGIN

    ALTER TABLE EDIControl DROP COLUMN AOMReg

    ALTER TABLE EDIControl DROP COLUMN AOMRegYear

    ALTER TABLE EDIControl DROP COLUMN AOMRegMonth

    PRINT 'Drop old AOM fields in EDIControl (02/18/2018)'

   END

  END

GO



PRINT 'Checking table EDIChangeDetail'



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIChangeDetail') = 0

BEGIN

    CREATE TABLE EDIChangeDetail(

     ChangeNumber             DECIMAL(9,0)        NOT NULL, 

     Line                     DECIMAL(9,0)        NOT NULL, 

     Tab                      VARCHAR(50)         NULL,

     Name                     VARCHAR(50)         NULL,

     PreviousValue            VARCHAR(200)        NULL,

     NewValue                 VARCHAR(200)        NULL,

     TimeStamp                timestamp           NULL

     CONSTRAINT EDIChangeDetailKey PRIMARY KEY CLUSTERED

         (

          ChangeNumber,

          Line

         )

    )

    PRINT 'New table EDIChangeDetail (04/11/2021)'

END

GO



PRINT 'Checking table EDIChanges'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIChanges' AND COLUMN_NAME='ChangeType') = 0

BEGIN

  ALTER TABLE EDIChanges DROP CONSTRAINT EDIChangesKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIChanges' AND COLUMN_NAME='ChangeType') = 0

BEGIN

  ALTER TABLE EDIChanges ADD

     ChangeType               CHAR(1)   DEFAULT 'C' NOT NULL,

     StockCode                CHAR(30)            NULL,

     Description              CHAR(30)            NULL,

     Warehouse                CHAR(2)             NULL

  ALTER TABLE EDIChanges ADD

     CONSTRAINT EDIChangesKey PRIMARY KEY CLUSTERED

         (

          ChangeType,

          OrderNumber,

          Line

         )

  PRINT 'Modify table EDIChanges (09/30/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIChanges' AND COLUMN_NAME='OrderNumber') = 1

BEGIN

  ALTER TABLE EDIChanges DROP CONSTRAINT EDIChangesKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIChanges' AND COLUMN_NAME='OrderNumber') = 1

BEGIN

  EXEC sp_rename 'EDIChanges.OrderNumber',        'SalesOrder',       'COLUMN';

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIChanges' and COLUMN_NAME='SalesOrder' and CHARACTER_MAXIMUM_LENGTH=15) = 1

BEGIN

    ALTER TABLE EDIChanges ALTER COLUMN SalesOrder  CHAR(20) NOT NULL

    ALTER TABLE EDIChanges ALTER COLUMN OrderQty    DECIMAL(18,6)

    ALTER TABLE EDIChanges ALTER COLUMN OrderUom    CHAR(10)

    ALTER TABLE EDIChanges ALTER COLUMN NewOrderQty DECIMAL(18,6)

    ALTER TABLE EDIChanges ALTER COLUMN PriceUom    CHAR(10)

    ALTER TABLE EDIChanges ALTER COLUMN NewPriceUom CHAR(10)

    ALTER TABLE EDIChanges ALTER COLUMN Description CHAR(50)

    ALTER TABLE EDIChanges ALTER COLUMN Warehouse   CHAR(10)

    

    ALTER TABLE EDIChanges

     ADD CONSTRAINT EDIChangesKey PRIMARY KEY CLUSTERED

       (

         ChangeType,

         SalesOrder,

         Line

       )

    PRINT 'Change columns EDIChanges (06/10/2013)'

END

GO



PRINT 'Checking table EDIChangeHeader'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIChangeHeader') = 0

BEGIN

    CREATE TABLE EDIChangeHeader(

     ChangeNumber             DECIMAL(9,0)        NOT NULL,

     ChangeDate               DATETIME            NULL,

     ChangeTime               DECIMAL(8,0)        NULL,

     Operator                 VARCHAR(20)         NULL,

     Program                  VARCHAR(6)          NULL,

     KeyDescription           VARCHAR(100)        NULL,

     Key1                     VARCHAR(50)         NULL,

     Key2                     VARCHAR(50)         NULL,

     Key3                     VARCHAR(50)         NULL,

     Key4                     VARCHAR(50)         NULL,

     TimeStamp                timestamp           NULL                                                                                          ,

     CONSTRAINT EDIChangeHeaderKey PRIMARY KEY CLUSTERED

         (

          ChangeNumber

         )

    )

    PRINT 'New table EDIChangeHeader (04/11/2021)'

END

GO



PRINT 'Checking table EDIComments'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIComments' and COLUMN_NAME='Code' and CHARACTER_MAXIMUM_LENGTH=15) = 1

BEGIN

  ALTER TABLE EDIComments DROP CONSTRAINT EDICommentsKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIComments' and COLUMN_NAME='Code' and CHARACTER_MAXIMUM_LENGTH=15) = 1

BEGIN

  DROP INDEX EDIComments.EDICommentsIdxCode2

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIComments' and COLUMN_NAME='Code' and CHARACTER_MAXIMUM_LENGTH=15) = 1

BEGIN

    ALTER TABLE EDIComments ALTER COLUMN Code        CHAR(20) NOT NULL

    ALTER TABLE EDIComments ALTER COLUMN Comment     CHAR(100)



 ALTER TABLE EDIComments

  ADD CONSTRAINT EDICommentsKey PRIMARY KEY CLUSTERED

  (

         KeyType,

         Code,

         Line,

         Code2,

         Sequence

  )



CREATE UNIQUE INDEX EDICommentsIdxCode2 ON EDIComments(

 KeyType,

 Code2,

 Code,

 Line,

 Sequence

 )

   

    PRINT 'Change columns EDIComments (06/10/2013)'

END

GO



PRINT 'Checking table EDIDocsToProcess'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIDocsToProcess' AND COLUMN_NAME='EDIDocument') = 0

BEGIN

 IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIDocsToProcess' AND COLUMN_NAME='Document') = 0

 BEGIN

    ALTER TABLE EDIDocsToProcess ADD

      EDIDocument             CHAR(6)             NULL

    PRINT 'New column EDIDocsToProcess...EDIDocument (12/19/2008)'

 END

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIDocsToProcess' AND COLUMN_NAME='Sequence') = 0

BEGIN

    ALTER TABLE EDIDocsToProcess ADD

     Sequence                 DECIMAL(10,0)       NULL

    PRINT 'New column EDIDocsToProcess...Sequence (07/13/2010)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIDocsToProcess' AND COLUMN_NAME='Extra') = 0

BEGIN

    ALTER TABLE EDIDocsToProcess ADD

     Extra                    CHAR(30)            NULL,

     Sort                     CHAR(10)            NULL

    PRINT 'New columns EDIDocsToProcess (03/28/2011)'

  IF (dbo.CadacusIndexTest('EDIDocsToProcessIdxSeq') = 1)

  BEGIN

    DROP INDEX EDIDocsToProcess.EDIDocsToProcessIdxSeq

  END

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIDocsToProcess' AND COLUMN_NAME='Document') = 0

BEGIN

  IF (dbo.CadacusIndexTest('EDIDocsToProcessIdxSeq') = 1)

  BEGIN

    DROP INDEX EDIDocsToProcess.EDIDocsToProcessIdxSeq

  END

  IF (dbo.CadacusIndexTest('EDIDocsToProcessKey') = 1)

  BEGIN

    ALTER TABLE EDIDocsToProcess DROP CONSTRAINT EDIDocsToProcessKey

  END

  EXEC sp_rename 'EDIDocsToProcess.Code',        'Document',       'COLUMN';

  EXEC sp_rename 'EDIDocsToProcess.EDIDocument', 'Processor',      'COLUMN';

END

GO



IF (SELECT IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIDocsToProcess' AND COLUMN_NAME='Processor') = 'YES'

BEGIN

  UPDATE EDIDocsToProcess SET Processor='      ' WHERE Processor IS NULL

  ALTER TABLE EDIDocsToProcess ALTER COLUMN Processor CHAR(6) NOT NULL

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIDocsToProcess' AND COLUMN_NAME='EntryDate') = 0

BEGIN

  ALTER TABLE EDIDocsToProcess ADD

     EntryDate             DATETIME            NULL,

     EntryTime             DECIMAL(8,0)        NULL

  ALTER TABLE EDIDocsToProcess DROP COLUMN TrackingDate

  PRINT 'New columns EDIDocsToProcess (04/13/2011)'

END

GO



IF (dbo.CadacusIndexTest('EDIDocsToProcessKey') = 0)

BEGIN

  ALTER TABLE EDIDocsToProcess

  ADD CONSTRAINT EDIDocsToProcessKey PRIMARY KEY CLUSTERED

  (

         KeyType,

         Document,

         Processor

  )

END

GO



IF (dbo.CadacusIndexTest('EDIDocsToProcessIdxSeq') = 0)

BEGIN

    CREATE UNIQUE INDEX EDIDocsToProcessIdxSeq ON EDIDocsToProcess(

     Processor,

     Sort,

     Sequence,

     KeyType,

     Document

     )

  PRINT 'Adding Index EDIDocsToProcessIdxSeq (04/13/2011)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIDocsToProcess' and COLUMN_NAME='Document' and CHARACTER_MAXIMUM_LENGTH=15) = 1

BEGIN

  ALTER TABLE EDIDocsToProcess DROP CONSTRAINT EDIDocsToProcessKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIDocsToProcess' and COLUMN_NAME='Document' and CHARACTER_MAXIMUM_LENGTH=15) = 1

BEGIN

  DROP INDEX EDIDocsToProcess.EDIDocsToProcessIdxSeq

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIDocsToProcess' and COLUMN_NAME='Document' and CHARACTER_MAXIMUM_LENGTH=15) = 1

BEGIN

  ALTER TABLE EDIDocsToProcess ALTER COLUMN Document  CHAR(20) NOT NULL

    

  ALTER TABLE EDIDocsToProcess

    ADD CONSTRAINT EDIDocsToProcessKey PRIMARY KEY CLUSTERED

     (

         KeyType,

         Document,

         Processor

     )

  CREATE UNIQUE INDEX EDIDocsToProcessIdxSeq ON EDIDocsToProcess(

    Processor,

    Sort,

    Sequence,

    KeyType,

    Document

    )

    PRINT 'Change columns EDIDocsToProcess (06/10/2013)'

END

GO



PRINT 'Checking table EDIDocuments'

GO

--  Add new 'EDIDocuments' Table

IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIDocuments') = 0

BEGIN

    CREATE TABLE EDIDocuments(

     Type                     CHAR(1)             NOT NULL,

     SystemCode               CHAR(10)            NOT NULL,

     FirstKey                 CHAR(20)            NOT NULL,

     SecondKey                CHAR(20)            NOT NULL,

     ThirdKey                 CHAR(20)            NOT NULL,

     DocumentDate             DATETIME            NULL,

     DocumentTime             DECIMAL(8,0)        NULL,

     DocumentFile             CHAR(200)           NULL,

     Program                  CHAR(6)             NULL,

     Operator                 CHAR(10)            NULL,

     ReverseDate              DECIMAL(9,0)        NULL,

     ReverseTime              DECIMAL(8,0)        NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIDocumentsKey PRIMARY KEY CLUSTERED

         (

          Type,

          SystemCode,

          FirstKey,

          SecondKey,

          ThirdKey

         )

    )

    PRINT 'New table EDIDocuments'

END

GO



EXEC dbo.CadacusNewColumn        '11/04/2018','C','EDIDocuments','Printer',60,0

EXEC dbo.CadacusNewColumn        '11/04/2018','N','EDIDocuments','Copies',2,0

EXEC dbo.CadacusNewColumn        '11/04/2018','C','EDIDocuments','Method',1,0

EXEC dbo.CadacusNewColumn        '11/04/2018','C','EDIDocuments','Location',1,0



PRINT 'Checking table EDIExternalLog'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIExternalLog') = 0

BEGIN

    CREATE TABLE EDIExternalLog(

     LogDate                  DATETIME            NOT NULL,

     LogTime                  DECIMAL(8,0)        NOT NULL,

     QueueCode                CHAR(20)            NOT NULL,

     ResponseKey              CHAR(50)            NOT NULL,

     StatusCode               CHAR(1)             NULL,

     Status                   CHAR(200)           NULL,

     Info                     CHAR(1000)          NULL,

     Response                 CHAR(1000)           NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIExternalLogKey PRIMARY KEY CLUSTERED

         (

          LogDate,

          LogTime,

          QueueCode,

          ResponseKey

         )

    )

    PRINT 'New table EDIExternalLog'

END

GO



EXEC dbo.CadacusAlterColumn      '04/01/2016','C','EDIExternalLog','Response',800,0

EXEC dbo.CadacusNewColumn        '04/01/2016','C','EDIExternalLog','ExceptionDetail',800,0

EXEC dbo.CadacusDropPrimaryKey   'EDIExternalLog','System',10

EXEC dbo.CadacusNewColumnNotNull '12/16/2016','C','EDIExternalLog','System',10,0

EXEC dbo.CadacusAddPrimaryKey    'EDIExternalLog','LogDate, LogTime, System, QueueCode, ResponseKey'

GO



PRINT 'Checking table EDIExternalQueue'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIExternalQueue') = 0

BEGIN

    CREATE TABLE EDIExternalQueue(

     Priority                 CHAR(1)             NOT NULL,

     EntryDate                DATETIME            NOT NULL,

     EntryTime                DECIMAL(8,0)        NOT NULL,

     Counter                  DECIMAL(6,0)        NOT NULL,

     QueueCode                CHAR(20)            NOT NULL,

     OperatorCode             CHAR(20)            NULL,

     Response                 CHAR(1)             NULL,

     ResponseKey              CHAR(50)            NULL,

     Info                     CHAR(1000)          NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIExternalQueueKey PRIMARY KEY CLUSTERED

         (

          Priority,

          EntryDate,

          EntryTime,

          Counter,

          QueueCode

         )

    )

    PRINT 'New table EDIExternalQueue'

END

GO



EXEC dbo.CadacusDropPrimaryKey   'EDIExternalQueue','System',10

EXEC dbo.CadacusNewColumnNotNull '12/16/2016','C','EDIExternalQueue','System',10,0

EXEC dbo.CadacusAddPrimaryKey    'EDIExternalQueue','System, Priority, EntryDate, EntryTime, Counter, QueueCode'

EXEC dbo.CadacusAddIndex         'EDIExternalQueue', 'Code', 'QueueCode, System, Priority, OperatorCode, EntryDate, EntryTime, Counter'



PRINT 'Checking table EDIExternalResp'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIExternalResp') = 0

BEGIN

    CREATE TABLE EDIExternalResp(

     QueueCode                CHAR(20)            NOT NULL,

     ResponseKey              CHAR(50)            NOT NULL,

     ResponseDate             DATETIME            NULL,

     ResponseTime             DECIMAL(8,0)        NULL,

     Response                 CHAR(1000)          NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIExternalRespKey PRIMARY KEY CLUSTERED

         (

          QueueCode,

          ResponseKey

         )

    )

    PRINT 'New table EDIExternalResp'

END

GO



EXEC dbo.CadacusDropPrimaryKey   'EDIExternalResp','System',10

EXEC dbo.CadacusNewColumnNotNull '12/16/2016','C','EDIExternalResp','System',10,0

EXEC dbo.CadacusAddPrimaryKey    'EDIExternalResp','System, QueueCode, ResponseKey'

GO



PRINT 'Checking table EDIImportDetail'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIImportDetail' and COLUMN_NAME='SalesOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  ALTER TABLE EDIImportDetail DROP CONSTRAINT EDIImportDetailKey

  DROP INDEX EDIImportDetail.EDIImportDetailIdxDateTime

  DECLARE @UPD NCHAR(200)

  SET @UPD=N'Update EDIImportDetail SET ShipDate=''20''+ShipDate WHERE ShipDate>''00000000'' AND ShipDate<''19000101'''

  EXEC sp_executesql @UPD

  SET @UPD=N'Update EDIImportDetail SET ShipDate=''19000101'' WHERE ShipDate<''19000101'''

  EXEC sp_executesql @UPD

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIImportDetail' and COLUMN_NAME='SalesOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  ALTER TABLE EDIImportDetail ALTER COLUMN ShipDate     DATETIME NOT NULL

  ALTER TABLE EDIImportDetail ALTER COLUMN Ordered      DECIMAL(18,6)

  ALTER TABLE EDIImportDetail ALTER COLUMN Shipped      DECIMAL(18,6)

  ALTER TABLE EDIImportDetail ALTER COLUMN Backordered  DECIMAL(18,6)

  ALTER TABLE EDIImportDetail ALTER COLUMN SalesOrder   CHAR(20)

  ALTER TABLE EDIImportDetail ALTER COLUMN CustomerCode CHAR(30)

  ALTER TABLE EDIImportDetail ALTER COLUMN UPCInfo      CHAR(30)

  ALTER TABLE EDIImportDetail ALTER COLUMN PODate       DATETIME

  ALTER TABLE EDIImportDetail ADD          ImportDate   DATETIME

  ALTER TABLE EDIImportDetail ADD          ImportTime   CHAR(8)



  ALTER TABLE EDIImportDetail

    ADD CONSTRAINT EDIImportDetailKey PRIMARY KEY CLUSTERED

     (

         Partner,

         Document,

         StockCode,

         Location,

         ShipDate

     )

  CREATE UNIQUE INDEX EDIImportDetailIdxDateTime ON EDIImportDetail(

    ImportDate,

    ImportTime,

    Document,

    StockCode,

    Ordered,

    Location,

    ShipDate

    )

    

    PRINT 'Change columns EDIImportDetail (06/10/2013)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIImportDetail' and COLUMN_NAME='DateTime') = 1

BEGIN

  DECLARE @UPD NCHAR(200)

  SET @UPD=N'UPDATE EDIImportDetail SET ImportDate=''19000101'' WHERE [DateTime]<''000001'''

  EXEC sp_executesql @UPD

  SET @UPD=N'UPDATE EDIImportDetail SET ImportDate=SUBSTRING([DateTime],1,8), ImportTime=SUBSTRING([DateTime],9,6) WHERE [DateTime]>''010100'''

  EXEC sp_executesql @UPD

  	

  ALTER TABLE EDIImportDetail DROP COLUMN [DateTime]

END

GO



EXEC dbo.CadacusNewColumn        '09/30/2021','N','EDIImportDetail','SalesOrderLine',4,0

EXEC dbo.CadacusNewColumn        '09/30/2021','N','EDIImportDetail','EDIPrice',15,5



PRINT 'Checking table EDIJobIssueItem'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIJobIssueItem') = 0

BEGIN

    CREATE TABLE EDIJobIssueItem(

     Issue                    DECIMAL(9,0)        NOT NULL,

     ItemNumber               DECIMAL(9,0)        NOT NULL,

     Status                   CHAR(1)             NULL,

     Job                      CHAR(8)             NULL,

     Line                     CHAR(2)             NULL,

     StockCode                CHAR(30)            NULL,

     Warehouse                CHAR(2)             NULL,

     Quantity                 DECIMAL(10,3)       NULL,

     Serial                   CHAR(20)            NULL,

     Lot                      CHAR(10)            NULL,

     Bin                      CHAR(6)             NULL,

     NumberOfDecimals         DECIMAL(1,0)        NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIJobIssueItemKey PRIMARY KEY CLUSTERED

         (

          Issue,

          ItemNumber

         )

    )

    CREATE UNIQUE INDEX EDIJobIssueItemIdxStock ON EDIJobIssueItem(

     StockCode,

     Issue,

     ItemNumber

     )

    PRINT 'New table EDIJobIssueItem'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIJobIssueItem' and COLUMN_NAME='Job' and CHARACTER_MAXIMUM_LENGTH=8) = 1

BEGIN

  ALTER TABLE EDIJobIssueItem ALTER COLUMN Job         CHAR(20)

  ALTER TABLE EDIJobIssueItem ALTER COLUMN Warehouse   CHAR(10)

  ALTER TABLE EDIJobIssueItem ALTER COLUMN Quantity    DECIMAL(18,6)

  ALTER TABLE EDIJobIssueItem ALTER COLUMN Serial      CHAR(50)

  ALTER TABLE EDIJobIssueItem ALTER COLUMN Lot         CHAR(50)

  ALTER TABLE EDIJobIssueItem ALTER COLUMN Bin         CHAR(20)



  PRINT 'Change columns EDIJobIssueItem (06/10/2013)'

END

GO



PRINT 'Checking table EDIJobIssueJob'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIJobIssueJob') = 0

BEGIN

    CREATE TABLE EDIJobIssueJob(

     Issue                    DECIMAL(9,0)        NOT NULL,

     Job                      CHAR(8)             NOT NULL,

     Status                   CHAR(1)             NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIJobIssueJobKey PRIMARY KEY CLUSTERED

         (

          Issue,

          Job

         )

    )

    PRINT 'New table EDIJobIssueJob'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIJobIssueJob' and COLUMN_NAME='Job' and CHARACTER_MAXIMUM_LENGTH=8) = 1

BEGIN

  ALTER TABLE EDIJobIssueJob DROP CONSTRAINT EDIJobIssueJobKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIJobIssueJob' and COLUMN_NAME='Job' and CHARACTER_MAXIMUM_LENGTH=8) = 1

BEGIN

  ALTER TABLE EDIJobIssueJob ALTER COLUMN Job         CHAR(20) NOT NULL



 ALTER TABLE EDIJobIssueJob

  ADD CONSTRAINT EDIJobIssueJobKey PRIMARY KEY CLUSTERED

  (

         Issue,

         Job

  )



  PRINT 'Change columns EDIJobIssueJob (06/10/2013)'

END

GO



PRINT 'Checking table EDIJobIssueMaster'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIJobIssueMaster') = 0

BEGIN

    CREATE TABLE EDIJobIssueMaster(

     Issue                    DECIMAL(9,0)        NOT NULL,

     Status                   CHAR(1)             NULL,

     ItemCount                DECIMAL(9,0)        NULL,

     Employee                 CHAR(6)             NULL,

     IssueDate                DATETIME            NULL,

     TimeMark                 CHAR(16)            NULL,

     YearPost                 DECIMAL(4,0)        NULL,

     MonthPost                DECIMAL(2,0)        NULL,

     Journal                  DECIMAL(5,0)        NULL,

     Handheld                 CHAR(20)            NULL,

     HandheldEmp              CHAR(6)             NULL,

     ExportDate               DATETIME            NULL,

     ExportTime               DECIMAL(8,0)        NULL,

     ImportDate               DATETIME            NULL,

     ImportTime               DECIMAL(8,0)        NULL,

     SaveDate                 DATETIME            NULL,

     SaveTime                 DECIMAL(8,0)        NULL,

     SaveElapsed              DECIMAL(9,0)        NULL,

     Splits                   DECIMAL(4,0)        NULL,

     ActiveSplits             DECIMAL(4,0)        NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIJobIssueMasterKey PRIMARY KEY CLUSTERED

         (

          Issue

         )

    )

    PRINT 'New table EDIJobIssueMaster'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIJobIssueMaster' and COLUMN_NAME='Employee' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  ALTER TABLE EDIJobIssueMaster ALTER COLUMN Employee    CHAR(20)

  ALTER TABLE EDIJobIssueMaster ALTER COLUMN Journal     DECIMAL(10,0)

  ALTER TABLE EDIJobIssueMaster ALTER COLUMN HandheldEmp CHAR(20)



  PRINT 'Change columns EDIJobIssueMaster (06/10/2013)'

END

GO



PRINT 'Checking table EDIJournal'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIJournal' and COLUMN_NAME='JournalTime' and CHARACTER_MAXIMUM_LENGTH=4) = 1

BEGIN

  ALTER TABLE EDIJournal ALTER COLUMN JournalDate   DATETIME

  ALTER TABLE EDIJournal ALTER COLUMN JournalTime   CHAR(8)

  ALTER TABLE EDIJournal ALTER COLUMN Operator      CHAR(20)

  ALTER TABLE EDIJournal ALTER COLUMN StartOrder    CHAR(20)

  ALTER TABLE EDIJournal ALTER COLUMN EndOrder      CHAR(20)

  ALTER TABLE EDIJournal ALTER COLUMN StartInvoice  CHAR(20)

  ALTER TABLE EDIJournal ALTER COLUMN EndInvoice    CHAR(20)

  ALTER TABLE EDIJournal ALTER COLUMN StartDispatch CHAR(20)

  ALTER TABLE EDIJournal ALTER COLUMN EndDispatch   CHAR(20)

  ALTER TABLE EDIJournal DROP  COLUMN StartJournal  

  ALTER TABLE EDIJournal DROP  COLUMN EndJournal    

  ALTER TABLE EDIJournal ALTER COLUMN DocumentFile  CHAR(255)



  PRINT 'Change columns EDIJournal (06/10/2013)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIJournal' and COLUMN_NAME='StartJournal') = 0

BEGIN

  ALTER TABLE EDIJournal ADD StartJournal  DECIMAL(10,0)

  ALTER TABLE EDIJournal ADD EndJournal    DECIMAL(10,0)



  PRINT 'Add back journal numbers to EDIJournal (06/10/2013)'

END

GO



PRINT 'Checking table EDILabelAddress'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelAddress' and COLUMN_NAME='SalesOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  ALTER TABLE EDILabelAddress DROP CONSTRAINT EDILabelAddressKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelAddress' and COLUMN_NAME='SalesOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

    ALTER TABLE EDILabelAddress ALTER COLUMN SalesOrder CHAR(20) NOT NULL

  ALTER TABLE EDILabelAddress

    ADD CONSTRAINT EDILabelAddressKey PRIMARY KEY CLUSTERED

    (

         Shipment,

         SalesOrder,

         Number

    )

  PRINT 'Change columns EDILabelAddress (06/10/2013)'

END

GO



PRINT 'Checking table EDILabelComments'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelComments' AND COLUMN_NAME='Type') = 0

BEGIN

  IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE

		WHERE TABLE_NAME='EDILabelComments' AND CONSTRAINT_NAME='EDILabelCommentsKey') = 1

  BEGIN

    ALTER TABLE EDILabelComments DROP CONSTRAINT EDILabelCommentsKey

  END

  ALTER TABLE EDILabelComments ADD Type    CHAR(1)  NOT NULL DEFAULT SPACE(1)

  ALTER TABLE EDILabelComments ADD Code    CHAR(10) NOT NULL DEFAULT SPACE(10)

  ALTER TABLE EDILabelComments ADD Line    DECIMAL(5,0) NOT NULL DEFAULT 0

  ALTER TABLE EDILabelComments ALTER COLUMN Counter DECIMAL(5,0) NOT NULL

  EXEC sp_rename 'EDILabelComments.CommentInfo',      'Info',      'COLUMN';

  ALTER TABLE EDILabelComments ALTER COLUMN Info CHAR(50) NULL

  ALTER TABLE EDILabelComments DROP COLUMN Filler

  ALTER TABLE EDILabelComments 

  	ADD CONSTRAINT EDILabelCommentsKey PRIMARY KEY CLUSTERED

         (

          Keymark,

          Type,

          Code,

          Line,

          Counter

         )

    PRINT 'Modify table EDILabelComments (07/06/2009)'

END

GO



PRINT 'Checking table EDILabelDetail'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelDetail' AND COLUMN_NAME='UserDef') = 0

BEGIN

    ALTER TABLE EDILabelDetail ADD UserDef char(4) NULL

    PRINT 'New column EDILabelDetail..UserDef'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelDetail' AND COLUMN_NAME='PurchaseOrder') = 0

BEGIN

    ALTER TABLE EDILabelDetail ADD PurchaseOrder char(30) NULL

    PRINT 'New column EDILabelDetail..PurchaseOrder'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelDetail' AND COLUMN_NAME='SalesOrder') = 0

BEGIN

    ALTER TABLE EDILabelDetail ADD SalesOrder char(6) NULL

    PRINT 'New column EDILabelDetail..SalesOrder'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelDetail' AND COLUMN_NAME='Serial') = 0

BEGIN

    ALTER TABLE EDILabelDetail ADD Serial char(20) NULL

    PRINT 'New column EDILabelDetail..Serial (07/29/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelDetail' and COLUMN_NAME='Ius1' and CHARACTER_MAXIMUM_LENGTH=10) = 1

BEGIN

  ALTER TABLE EDILabelDetail DROP CONSTRAINT EDILabelDetailKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelDetail' and COLUMN_NAME='Ius1' and CHARACTER_MAXIMUM_LENGTH=10) = 1

BEGIN

    ALTER TABLE EDILabelDetail ALTER COLUMN Counter            DECIMAL(5,0) NOT NULL

    ALTER TABLE EDILabelDetail ALTER COLUMN Quantity           DECIMAL(18,6)

    ALTER TABLE EDILabelDetail ALTER COLUMN Ius1               CHAR(30)

    ALTER TABLE EDILabelDetail ALTER COLUMN Description        CHAR(50)

    ALTER TABLE EDILabelDetail ALTER COLUMN LongDescription    CHAR(100)

    ALTER TABLE EDILabelDetail ALTER COLUMN UnitOfMeasure      CHAR(10)

    ALTER TABLE EDILabelDetail ALTER COLUMN AlternateUOM       CHAR(10)

    ALTER TABLE EDILabelDetail ALTER COLUMN Lot                CHAR(50)

    ALTER TABLE EDILabelDetail ALTER COLUMN LotQuantity        DECIMAL(18,6)

    ALTER TABLE EDILabelDetail ALTER COLUMN Altkey2            CHAR(20)

    ALTER TABLE EDILabelDetail ALTER COLUMN ConvFactAltUOM     DECIMAL(12,6)

    ALTER TABLE EDILabelDetail ALTER COLUMN ConvFactOthUOM     DECIMAL(12,6)

    ALTER TABLE EDILabelDetail ALTER COLUMN Mass               DECIMAL(18,6)

    ALTER TABLE EDILabelDetail ALTER COLUMN Volume             DECIMAL(18,6)

    ALTER TABLE EDILabelDetail ALTER COLUMN Warehouse          CHAR(10)

    ALTER TABLE EDILabelDetail ALTER COLUMN DefaultBin         CHAR(20)

    ALTER TABLE EDILabelDetail ALTER COLUMN OrderQuantity      DECIMAL(18,6)

    ALTER TABLE EDILabelDetail ALTER COLUMN ToShipQuantity     DECIMAL(18,6)

    ALTER TABLE EDILabelDetail ALTER COLUMN TotalShipped       DECIMAL(18,6)

    ALTER TABLE EDILabelDetail ALTER COLUMN OtherUnitOfMeasure CHAR(10)

    ALTER TABLE EDILabelDetail ALTER COLUMN SalesOrder         CHAR(20)

    ALTER TABLE EDILabelDetail ALTER COLUMN Serial             CHAR(50)



ALTER TABLE EDILabelDetail

  ADD CONSTRAINT EDILabelDetailKey PRIMARY KEY CLUSTERED

  (

         Keymark,

         Counter

  )

  PRINT 'Change columns EDILabelDetail (06/10/2013)'

END

GO



EXEC dbo.CadacusNewColumn    '11/03/2021','C','EDILabelDetail','DispatchNote',20,0



PRINT 'Checking table EDILabelMaster'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelMaster' AND COLUMN_NAME='OrderDate') = 0

BEGIN

    ALTER TABLE EDILabelMaster ADD OrderDate datetime NULL

    PRINT 'New column EDILabelMaster..OrderDate'

END

GO



IF (dbo.CadacusIndexTest('EDILabelMasterIdxShipment') = 0)

BEGIN

  CREATE UNIQUE INDEX EDILabelMasterIdxShipment ON EDILabelMaster(

   Shipment,

   Tare,

   Pack,

   Keymark

   )

  PRINT 'Adding Index EDILabelMasterIdxShipment (11/24/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelMaster' AND COLUMN_NAME='ShipDate') = 0

BEGIN

    ALTER TABLE EDILabelMaster ADD ShipDate DATETIME NULL

    PRINT 'New column EDILabelMaster..ShipDate (07/31/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelMaster' AND COLUMN_NAME='Tracking') = 0

BEGIN

    ALTER TABLE EDILabelMaster ADD

     Tracking                 CHAR(25)            NULL

    PRINT 'New column EDILabelMaster (04/04/2011)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelMaster' AND COLUMN_NAME='Length') = 0

BEGIN

    ALTER TABLE EDILabelMaster ADD

     Length                   DECIMAL(6,2)        NULL,

     Width                    DECIMAL(6,2)        NULL,

     Height                   DECIMAL(6,2)        NULL,

     DimensionsUOM            CHAR(2)             NULL

    PRINT 'New column EDILabelMaster (06/19/2012)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelMaster' AND COLUMN_NAME='FreightActual') = 0

BEGIN

    ALTER TABLE EDILabelMaster ADD

     FreightActual            DECIMAL(9,2)        NULL,

     FreightCost              DECIMAL(9,2)        NULL,

     FreightCharge            DECIMAL(9,2)        NULL

    PRINT 'New column EDILabelMaster (07/21/2012)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelMaster' AND COLUMN_NAME='Length' AND NUMERIC_SCALE=0) = 1

BEGIN

    ALTER TABLE EDILabelMaster ALTER COLUMN Length DECIMAL(6,2)

    ALTER TABLE EDILabelMaster ALTER COLUMN Width  DECIMAL(6,2)

    ALTER TABLE EDILabelMaster ALTER COLUMN Height DECIMAL(6,2)

    PRINT 'Change columns EDILabelMaster (02/16/2013)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelMaster' AND COLUMN_NAME='PackNumber') = 0

BEGIN

    ALTER TABLE EDILabelMaster ADD

     PackNumber               DECIMAL(6,0)        NULL,

     PackTotal                DECIMAL(6,0)        NULL

    PRINT 'New column EDILabelMaster (02/19/2013)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelMaster' and COLUMN_NAME='LabelDate' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

    ALTER TABLE EDILabelMaster ALTER COLUMN LabelDate CHAR(8)



  DECLARE @UPD NCHAR(200)

  SET @UPD=N'Update EDILabelMaster SET LabelDate=''20''+SUBSTRING(LabelDate,5,2)+SUBSTRING(LabelDate,1,4) WHERE LabelDate>''00000000'' AND LabelDate<''19000101'''

  EXEC sp_executesql @UPD

  SET @UPD=N'Update EDILabelMaster SET LabelDate=''19000101'' WHERE LabelDate<''19000101'''

  EXEC sp_executesql @UPD



   -- Update EDILabelMaster SET LabelDate='20'+SUBSTRING(LabelDate,5,2)+SUBSTRING(LabelDate,1,4) WHERE LabelDate>'00000000' AND LabelDate<'19000101'

   -- Update EDILabelMaster SET LabelDate='19000101' WHERE LabelDate<'19000101'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelMaster' and COLUMN_NAME='Via' and CHARACTER_MAXIMUM_LENGTH=15) = 1

BEGIN

    ALTER TABLE EDILabelMaster ALTER COLUMN LabelFile         CHAR(255)

    ALTER TABLE EDILabelMaster ALTER COLUMN Via               CHAR(50)

    ALTER TABLE EDILabelMaster ADD          ViaCode           CHAR(6)

    ALTER TABLE EDILabelMaster ALTER COLUMN SalesOrder        CHAR(20)

    ALTER TABLE EDILabelMaster ALTER COLUMN PurchaseOrder     CHAR(30)

    ALTER TABLE EDILabelMaster ALTER COLUMN Counter           DECIMAL(5,0)

    ALTER TABLE EDILabelMaster ALTER COLUMN Carrier           CHAR(50)

    ALTER TABLE EDILabelMaster ALTER COLUMN ProNumber         CHAR(50)

    ALTER TABLE EDILabelMaster ALTER COLUMN BillOfLading      CHAR(50)

    ALTER TABLE EDILabelMaster ALTER COLUMN Station           CHAR(10)

    ALTER TABLE EDILabelMaster ALTER COLUMN MultCode          CHAR(20)

    ALTER TABLE EDILabelMaster ALTER COLUMN Operator          CHAR(20)

    ALTER TABLE EDILabelMaster ALTER COLUMN StationOper       CHAR(20)

    ALTER TABLE EDILabelMaster ALTER COLUMN LabelDate         DATETIME

    ALTER TABLE EDILabelMaster ALTER COLUMN LabelTime         CHAR(8)

    ALTER TABLE EDILabelMaster ALTER COLUMN Employee          CHAR(20)

    ALTER TABLE EDILabelMaster ALTER COLUMN Customer          CHAR(15)

    ALTER TABLE EDILabelMaster ALTER COLUMN Dispatch          CHAR(20)

    ALTER TABLE EDILabelMaster ALTER COLUMN FreightActual     DECIMAL(14,2)

    ALTER TABLE EDILabelMaster ALTER COLUMN FreightCost       DECIMAL(14,2)

    ALTER TABLE EDILabelMaster ALTER COLUMN FreightCharge     DECIMAL(14,2)

    

    PRINT 'Change columns EDILabelMaster (06/10/2013)'

END

GO



EXEC dbo.CadacusNewColumn    '08/30/2016','C','EDILabelMaster','DGFlag',1,0

EXEC dbo.CadacusNewColumn    '11/03/2021','N','EDILabelMaster','Document',9,0



PRINT 'Checking table EDILabelPackage'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelPackage' AND COLUMN_NAME='SerialNumber') = 0

BEGIN

    ALTER TABLE EDILabelPackage ADD SerialNumber char(25) NULL

    PRINT 'New Column EDILabelPackage..SerialNumber (02/04/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelPackage' AND COLUMN_NAME='Contents') = 0

BEGIN

    ALTER TABLE EDILabelPackage ADD 

     Contents                 CHAR(35)            NULL,

     Addl1                    CHAR(10)            NULL,

     Addl2                    CHAR(20)            NULL

    PRINT 'New columns to EDILabelPackage (12/31/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelPackage' AND COLUMN_NAME='Ref1') = 0

BEGIN

    ALTER TABLE EDILabelPackage ADD 

     Ref1                     CHAR(35)            NULL,

     Ref2                     CHAR(35)            NULL

    PRINT 'New columns to EDILabelPackage (05/26/2010)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelPackage' AND COLUMN_NAME='Barcode') = 0

BEGIN

    ALTER TABLE EDILabelPackage ADD 

     Barcode                  CHAR(40)            NULL,

     AddrBarcode              CHAR(30)            NULL,

     Meter                    CHAR(9)             NULL

    PRINT 'New columns to EDILabelPackage (05/11/2011)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelPackage' AND COLUMN_NAME='BillAccount') = 0

BEGIN

    ALTER TABLE EDILabelPackage ADD 

     BillAccount              CHAR(12)            NULL,

     BillMethod               CHAR(1)             NULL

    PRINT 'New columns to EDILabelPackage (05/23/2011)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelPackage' AND COLUMN_NAME='Ref3') = 0

BEGIN

    ALTER TABLE EDILabelPackage ADD 

     Ref3                     CHAR(35)            NULL,

     Ref4                     CHAR(35)            NULL,

     Ref1Code                 CHAR(2)             NULL,

     Ref2Code                 CHAR(2)             NULL,

     Ref3Code                 CHAR(2)             NULL,

     Ref4Code                 CHAR(2)             NULL

    PRINT 'New columns to EDILabelPackage (11/14/2012)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelPackage' AND COLUMN_NAME='Tracking2') = 0

BEGIN

    ALTER TABLE EDILabelPackage ADD 

     Tracking2          CHAR(30)            NULL

    PRINT 'New column EDILabelPackage (04/29/2013)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILabelPackage' AND COLUMN_NAME='ShipperRelease') = 0

BEGIN

    ALTER TABLE EDILabelPackage ADD 

     ShipperRelease          CHAR(1)            NULL

    PRINT 'New column EDILabelPackage (05/08/2013)'

END

GO



PRINT 'Checking table EDILctVerifyItem'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDILctVerifyItem') = 0

BEGIN

    CREATE TABLE EDILctVerifyItem(

     LCTVerify                DECIMAL(9,0)        NOT NULL,

     ItemNumber               DECIMAL(9,0)        NOT NULL,

     Status                   CHAR(1)             NULL,

     ShipmentReference        CHAR(30)            NULL,

     PurchaseOrder            CHAR(20)            NULL,

     PurchaseOrderLin         DECIMAL(4,0)        NULL,

     StockCode                CHAR(30)            NULL,

     Quantity                 DECIMAL(18,6)       NULL,

     Counted                  DECIMAL(18,6)       NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDILctVerifyItemKey PRIMARY KEY CLUSTERED

         (

          LCTVerify,

          ItemNumber

         )

    )

    PRINT 'New table EDILctVerifyItem (12/03/2017)'

END

GO



PRINT 'Checking table EDILctVerifyMaster'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDILctVerifyMaster') = 0

BEGIN

    CREATE TABLE EDILctVerifyMaster(

     LCTVerify                DECIMAL(9,0)        NOT NULL,

     Status                   CHAR(1)             NULL,

     ItemCount                DECIMAL(9,0)        NULL,

     VerifyDate               DATETIME            NULL,

     TimeMark                 CHAR(16)            NULL,

     Handheld                 CHAR(20)            NULL,

     Employee                 CHAR(20)            NULL,

     ExportDate               DATETIME            NULL,

     ExportTime               DECIMAL(8,0)        NULL,

     ImportDate               DATETIME            NULL,

     ImportTime               DECIMAL(8,0)        NULL,

     SaveDate                 DATETIME            NULL,

     SaveTime                 DECIMAL(8,0)        NULL,

     SaveElapsed              DECIMAL(9,0)        NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDILctVerifyMasterKey PRIMARY KEY CLUSTERED

         (

          LCTVerify

         )

    )

    PRINT 'New table EDILctVerifyMaster (12/03/2017)'

END

GO



PRINT 'Checking table EDILog'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILog' and COLUMN_NAME='OperatorCode' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  ALTER TABLE EDILog DROP CONSTRAINT EDILogKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILog' and COLUMN_NAME='OperatorCode' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  EXEC sp_rename 'EDILog.OrderNumber',        'Code',       'COLUMN';

  EXEC sp_rename 'EDILog.PartnerCode',        'Partner',    'COLUMN';

  EXEC sp_rename 'EDILog.DocumentNumber',     'Document',   'COLUMN';

  EXEC sp_rename 'EDILog.OperatorCode',       'Operator',   'COLUMN';  

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILog' and COLUMN_NAME='Code' and CHARACTER_MAXIMUM_LENGTH=15) = 1

BEGIN

    ALTER TABLE EDILog ALTER COLUMN Code     CHAR(20) NOT NULL

    ALTER TABLE EDILog ALTER COLUMN Operator CHAR(20)

    

  ALTER TABLE EDILog

    ADD CONSTRAINT EDILogKey PRIMARY KEY CLUSTERED

    (

         Code,

         Partner,

         Document

    )

    PRINT 'Change columns EDILog (06/10/2013)'

END

GO



PRINT 'Checking table EDILPDetails'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDILPDetails') = 0

BEGIN

    CREATE TABLE EDILPDetails(

     Plate                    CHAR(50)            NOT NULL,

     Item                     CHAR(50)            NOT NULL,

     ItemType                 CHAR(1)             NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDILPDetailsKey PRIMARY KEY CLUSTERED

         (

          Plate,

          Item

         )

    )

    CREATE UNIQUE INDEX EDILPDetailsIdxItem ON EDILPDetails(

     Item,

     ItemType

     )

    PRINT 'New table EDILPDetails (02/18/2014)'

END

GO



PRINT 'Checking table EDILPItems'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDILPItems') = 0

BEGIN

    CREATE TABLE EDILPItems(

     Item                     CHAR(50)            NOT NULL,

     Plate                    CHAR(50)            NULL,

     Stock                    CHAR(50)            NULL,

     Quantity                 DECIMAL(18,6)       NULL,

     Lot                      CHAR(50)            NULL,

     Serial                   CHAR(50)            NULL,

     Weight                   DECIMAL(18,6)       NULL,

     User1                    CHAR(50)            NULL,

     User2                    CHAR(50)            NULL,

     User3                    CHAR(50)            NULL,

     User4                    CHAR(50)            NULL,

     User5                    CHAR(50)            NULL,

     Counter                  DECIMAL(5,0)        NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDILPItemsKey PRIMARY KEY CLUSTERED

         (

          Item

         )

    )

    CREATE UNIQUE INDEX EDILPItemsIdxUnique ON EDILPItems(

     Plate,

     Stock,

     Lot,

     Serial,

     Counter

     )



    PRINT 'New table EDILPItems (02/18/2014)'

END

GO



EXEC dbo.CadacusNewColumn '03/31/2014','C','EDILPItems','User1',50,0

EXEC dbo.CadacusNewColumn '03/31/2014','C','EDILPItems','User2',50,0

EXEC dbo.CadacusNewColumn '03/31/2014','C','EDILPItems','User3',50,0

EXEC dbo.CadacusNewColumn '03/31/2014','C','EDILPItems','User4',50,0

EXEC dbo.CadacusNewColumn '03/31/2014','C','EDILPItems','User5',50,0



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILPItems' AND COLUMN_NAME='Counter') = 0

BEGIN

  DROP INDEX EDILPItems.EDILPItemsIdxUnique

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDILPItems' AND COLUMN_NAME='Counter') = 0

BEGIN

    ALTER TABLE EDILPItems ADD

      Counter         DECIMAL(5,0)            NULL

    DECLARE @UPD NCHAR(100)

    SET @UPD=N'UPDATE EDILPItems SET Counter=0'

    EXEC sp_executesql @UPD

    CREATE UNIQUE INDEX EDILPItemsIdxUnique ON EDILPItems(

     Plate,

     Stock,

     Lot,

     Serial,

     Counter

     )



     PRINT 'New columns EDILPItems (10/20/2014)'

END

GO



EXEC dbo.CadacusAddIndex  'EDILPItems', 'Stk', 'Stock, Lot, Serial, Counter, Item'

EXEC dbo.CadacusNewColumn '12/15/2020','C','EDILPItems','Warehouse',10,0

EXEC dbo.CadacusNewColumn '09/13/2021','N','EDILPItems','PickQuantity',12,6



PRINT 'Checking table EDILPMaster'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDILPMaster') = 0

BEGIN

    CREATE TABLE EDILPMaster(

     Plate                    CHAR(50)            NOT NULL,

     UpdateDate               DATETIME            NULL,

     UpdateTime               DECIMAL(8,0)        NULL,

     ContainerType            CHAR(20)            NULL,

     Status                   CHAR(1)             NULL,

     BinLocation              CHAR(20)            NULL,

     Warehouse                CHAR(10)            NULL,

     SalesOrder               CHAR(20)            NULL,

     OriginalPO               CHAR(20)            NULL,

     Job                      CHAR(20)            NULL,

     Shipment                 DECIMAL(9,0)        NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDILPMasterKey PRIMARY KEY CLUSTERED

         (

          Plate

         )

    )

    CREATE UNIQUE INDEX EDILPMasterIdxStatus ON EDILPMaster(

     Status,

     Plate

     )

    PRINT 'New table EDILPMaster (02/18/2014)'

END

GO



EXEC dbo.CadacusNewColumn '03/31/2014','C','EDILPMaster','User1',50,0

EXEC dbo.CadacusNewColumn '03/31/2014','C','EDILPMaster','User2',50,0

EXEC dbo.CadacusNewColumn '03/31/2014','C','EDILPMaster','User3',50,0

EXEC dbo.CadacusNewColumn '03/31/2014','C','EDILPMaster','User4',50,0

EXEC dbo.CadacusNewColumn '03/31/2014','C','EDILPMaster','User5',50,0



EXEC dbo.CadacusNewColumn '04/23/2014','D','EDILPMaster','CreateDate',0,0

EXEC dbo.CadacusNewColumn '04/23/2014','N','EDILPMaster','CreateTime',8,0

EXEC dbo.CadacusNewColumn '04/23/2014','N','EDILPMaster','Weight',18,6



EXEC dbo.CadacusNewColumn '02/15/2017','N','EDILPMaster','Length',6,2

EXEC dbo.CadacusNewColumn '02/15/2017','N','EDILPMaster','Width',6,2

EXEC dbo.CadacusNewColumn '02/15/2017','N','EDILPMaster','Height',6,2



EXEC dbo.CadacusNewColumn '06/12/2017','C','EDILPMaster','StockTakeStatus',1,0

EXEC dbo.CadacusNewColumn '06/12/2017','D','EDILPMaster','StockTakeDate',0,0

EXEC dbo.CadacusNewColumn '06/12/2017','N','EDILPMaster','StockTakeTime',8,0



EXEC dbo.CadacusNewColumn '03/20/2019','C','EDILPMaster','GtrReference',20,0

EXEC dbo.CadacusNewColumn '03/20/2019','C','EDILPMaster','StatusMessage',50,0



EXEC dbo.CadacusNewColumn '01/24/2020','N','EDILPMaster','Operation',5,0

EXEC dbo.CadacusNewColumn '01/24/2020','C','EDILPMaster','Location',20,0



IF (dbo.CadacusIndexTest('EDILPMasterIdxSo') = 0)

BEGIN

 CREATE UNIQUE INDEX EDILPMasterIdxSo ON EDILPMaster(

  SalesOrder,

  Plate

  )

END  

GO



IF (dbo.CadacusIndexTest('EDILPMasterIdxPo') = 0)

BEGIN

 CREATE UNIQUE INDEX EDILPMasterIdxPo ON EDILPMaster(

  OriginalPO,

  Plate

  )

END  

GO



IF (dbo.CadacusIndexTest('EDILPMasterIdxJob') = 0)

BEGIN

  CREATE UNIQUE INDEX EDILPMasterIdxJob ON EDILPMaster(

   Job,

   Plate

   )

END  

GO



IF (dbo.CadacusIndexTest('EDILPMasterIdxShipment') = 0)

BEGIN

  CREATE UNIQUE INDEX EDILPMasterIdxShipment ON EDILPMaster(

   Shipment,

   Plate

   )

END  

GO



IF (dbo.CadacusIndexTest('EDILPMasterIdxUser1') = 0)

BEGIN

  CREATE UNIQUE INDEX EDILPMasterIdxUser1 ON EDILPMaster(

   User1,

   Plate

   )

END  

GO



IF (dbo.CadacusIndexTest('EDILPMasterIdxUser2') = 0)

BEGIN

  CREATE UNIQUE INDEX EDILPMasterIdxUser2 ON EDILPMaster(

   User2,

   Plate

   )

END  

GO



IF (dbo.CadacusIndexTest('EDILPMasterIdxUser3') = 0)

BEGIN

  CREATE UNIQUE INDEX EDILPMasterIdxUser3 ON EDILPMaster(

   User3,

   Plate

   )

END  

GO



IF (dbo.CadacusIndexTest('EDILPMasterIdxUser4') = 0)

BEGIN

  CREATE UNIQUE INDEX EDILPMasterIdxUser4 ON EDILPMaster(

   User4,

   Plate

   )

END  

GO



IF (dbo.CadacusIndexTest('EDILPMasterIdxUser5') = 0)

BEGIN

  CREATE UNIQUE INDEX EDILPMasterIdxUser5 ON EDILPMaster(

   User5,

   Plate

   )

END  

GO



IF (dbo.CadacusIndexTest('EDILPMasterIdxTake') = 0)

BEGIN

  CREATE UNIQUE INDEX EDILPMasterIdxTake ON EDILPMaster(

   StockTakeStatus,

   Warehouse,

   Plate

   )

END  

GO



PRINT 'Checking table EDILPTracking'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDILPTracking') = 0

BEGIN

    CREATE TABLE EDILPTracking(

     Plate                    CHAR(50)            NOT NULL,

     DateEntered              DATETIME            NOT NULL,

     TimeEntered              DECIMAL(8,0)        NOT NULL,

     Type                     CHAR(1)             NULL,

     Operator                 CHAR(20)            NULL,

     Handheld                 CHAR(20)            NULL,

     Employee                 CHAR(20)            NULL,

     Item                     CHAR(50)            NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDILPTrackingKey PRIMARY KEY CLUSTERED

         (

          Plate,

          DateEntered,

          TimeEntered

         )

    )

    PRINT 'New table EDILPTracking (02/18/2014)'

END

GO



EXEC dbo.CadacusNewColumn '02/23/2017','C','EDILPTracking','Info1',50,0

EXEC dbo.CadacusNewColumn '02/23/2017','C','EDILPTracking','Info2',50,0

EXEC dbo.CadacusNewColumn '02/23/2017','C','EDILPTracking','Info3',50,0

EXEC dbo.CadacusNewColumn '02/23/2017','C','EDILPTracking','Info4',50,0

EXEC dbo.CadacusNewColumn '09/04/2018','N','EDILPTracking','Quantity',18,6



PRINT 'Checking table EDIMasterDocument'

GO



EXEC dbo.CadacusNewColumn   '07/21/2009','C','EDIMasterDocument','AckFlag',1,0

EXEC dbo.CadacusNewColumn   '11/18/2009','C','EDIMasterDocument','SortSeq',1,0

EXEC dbo.CadacusNewColumn   '11/20/2010','C','EDIMasterDocument','ArchiveFlag',1,0

EXEC dbo.CadacusNewColumn   '08/07/2011','C','EDIMasterDocument','ScriptFile',100,0

EXEC dbo.CadacusNewColumn   '11/21/2011','C','EDIMasterDocument','POCheck',1,0

EXEC dbo.CadacusNewColumn   '12/09/2012','C','EDIMasterDocument','RunCombine',1,0

EXEC dbo.CadacusAlterColumn '06/10/2013','C','EDIMasterDocument','DocumentFile',200,0

EXEC dbo.CadacusNewColumn   '06/10/2013','N','EDIMasterDocument','InfoVersion',3,0

EXEC dbo.CadacusAlterColumn '07/24/2016','C','EDIMasterDocument','TransmissionID',35,0

EXEC dbo.CadacusAlterColumn '07/24/2016','C','EDIMasterDocument','Qualifier',4,0

EXEC dbo.CadacusAlterColumn '07/24/2016','C','EDIMasterDocument','PartnerID',35,0

EXEC dbo.CadacusAlterColumn '07/24/2016','C','EDIMasterDocument','PartnerQualifier',4,0

EXEC dbo.CadacusAlterColumn '07/24/2016','C','EDIMasterDocument','Security',14,0

EXEC dbo.CadacusNewColumn   '07/24/2016','C','EDIMasterDocument','SyntaxId',4,0

EXEC dbo.CadacusNewColumn   '08/02/2021','C','EDIMasterDocument','ScriptFlag',1,0





--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIMasterDocument' AND COLUMN_NAME='AckFlag') = 0

--BEGIN

--    ALTER TABLE EDIMasterDocument ADD

--     AckFlag           CHAR(1)            NULL

--    PRINT 'New columns EDIMasterDocument (07/21/2009)'

--END

--GO

--

--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIMasterDocument' AND COLUMN_NAME='SortSeq') = 0

--BEGIN

--    ALTER TABLE EDIMasterDocument ADD

--     SortSeq           CHAR(1)            NULL

--    PRINT 'New columns EDIMasterDocument (11/18/2009)'

--END

--GO

--

--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIMasterDocument' AND COLUMN_NAME='ArchiveFlag') = 0

--BEGIN

--    ALTER TABLE EDIMasterDocument ADD

--     ArchiveFlag           CHAR(1)            NULL

--    PRINT 'New columns EDIMasterDocument (11/30/2010)'

--END

--GO

--

--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIMasterDocument' AND COLUMN_NAME='ScriptFile') = 0

--BEGIN

--    ALTER TABLE EDIMasterDocument ADD

--     ScriptFile               CHAR(100)           NULL

--    PRINT 'New column EDIMasterDocument (08/07/2011)'

--END

--GO

--

--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIMasterDocument' AND COLUMN_NAME='POCheck') = 0

--BEGIN

--    ALTER TABLE EDIMasterDocument ADD

--     POCheck                  CHAR(1)             NULL

--    PRINT 'New columns EDIMasterDocument (11/21/2011)'

--END

--GO

--

--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIMasterDocument' AND COLUMN_NAME='RunCombine') = 0

--BEGIN

--    ALTER TABLE EDIMasterDocument ADD

--     RunCombine                  CHAR(1)             NULL

--    PRINT 'New columns EDIMasterDocument (12/09/2012)'

--END

--GO

--

--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIMasterDocument' and COLUMN_NAME='DocumentFile' and CHARACTER_MAXIMUM_LENGTH=100) = 1

--BEGIN

--  ALTER TABLE EDIMasterDocument ALTER COLUMN DocumentFile CHAR(200)

--  ALTER TABLE EDIMasterDocument ADD          InfoVersion  DECIMAL(3,0)

--  

--    PRINT 'Change columns EDIMasterDocument (06/10/2013)'

--END

--GO

--

--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIMasterDocument' and COLUMN_NAME='TransmissionID' and CHARACTER_MAXIMUM_LENGTH=15) = 1

--BEGIN

--  ALTER TABLE EDIMasterDocument ALTER COLUMN TransmissionID   CHAR(35)

--  ALTER TABLE EDIMasterDocument ALTER COLUMN Qualifier        CHAR(4)

--  ALTER TABLE EDIMasterDocument ALTER COLUMN PartnerID        CHAR(35)

--  ALTER TABLE EDIMasterDocument ALTER COLUMN PartnerQualifier CHAR(4)

--  ALTER TABLE EDIMasterDocument ALTER COLUMN Security         CHAR(14)

--  ALTER TABLE EDIMasterDocument ADD   SyntaxId  CHAR(4)  NULL

--  

--    PRINT 'Change columns EDIMasterDocument (07/24/2016)'

--END

--GO



PRINT 'Checking table EDIMasterHandhelds'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIMasterHandhelds') = 0

BEGIN

    CREATE TABLE EDIMasterHandhelds(

     Code                     CHAR(30)            NOT NULL,

     Record                   CHAR(10)            NOT NULL,

     Information              CHAR(1000)          NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIMasterHandheldsKey PRIMARY KEY CLUSTERED

         (

          Code,

          Record

         )

    )

    CREATE UNIQUE INDEX EDIMasterHandheldsIdxRecord ON EDIMasterHandhelds(

     Record,

     Code

     )

    PRINT 'New table EDIMasterHandhelds (01/26/2008)'

END

GO



--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIMasterHandhelds' and COLUMN_NAME='Information' and CHARACTER_MAXIMUM_LENGTH=1000) = 1

--BEGIN

--  ALTER TABLE EDIMasterHandhelds ALTER COLUMN Information  CHAR(2000)

--  ALTER TABLE EDIMasterHandhelds ADD          InfoVersion  DECIMAL(3,0)

--  

--    PRINT 'Change columns EDIMasterHandhelds (06/10/2013)'

--END

--GO



EXEC dbo.CadacusNewColumn   '06/10/2013','N','EDIMasterHandhelds','InfoVersion',3,0

EXEC dbo.CadacusAlterColumn '07/20/2017','C','EDIMasterHandhelds','Information',2950,0





PRINT 'Checking table EDIMasterInfo'

GO



IF (SELECT CHARACTER_MAXIMUM_LENGTH FROM INFORMATION_SCHEMA.COLUMNS 

    WHERE TABLE_NAME='EDIMasterInfo' AND COLUMN_NAME='RecordInfo') = 2000

BEGIN

  ALTER TABLE EDIMasterInfo 

	  ALTER COLUMN RecordInfo CHAR(2990)

  PRINT 'Increase Column Size EDIMasterInfo...RecordInfo (03/12/2009)'

END

GO



PRINT 'Checking table EDIMasterPartner'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIMasterPartner' AND COLUMN_NAME='PartnerGSCFFType') = 0

BEGIN

    ALTER TABLE EDIMasterPartner ADD PartnerGSCFFType char(6) NULL

    ALTER TABLE EDIMasterPartner ADD PartnerGSCFFName char(6) NULL

    PRINT 'Add Partner GS CFF columns to EDIMasterPartner (06/16/2007)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIMasterPartner' AND COLUMN_NAME='RoutingAddress') = 0

BEGIN

    ALTER TABLE EDIMasterPartner ADD

     RoutingAddress           CHAR(14)            NULL,

     ReverseRouting           CHAR(14)            NULL,

     AssociationCode          CHAR(6)             NULL

    PRINT 'New columns EDIMasterPartner (08/26/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIMasterPartner' and COLUMN_NAME='Name' and CHARACTER_MAXIMUM_LENGTH=30) = 1

BEGIN

    ALTER TABLE EDIMasterPartner ALTER COLUMN Name   CHAR(50)

    ALTER TABLE EDIMasterPartner ALTER COLUMN Master CHAR(15)

    ALTER TABLE EDIMasterPartner ALTER COLUMN Prefix CHAR(15)

    ALTER TABLE EDIMasterPartner ALTER COLUMN Format CHAR(2)

    ALTER TABLE EDIMasterPartner ALTER COLUMN Number CHAR(50)

    PRINT 'Change columns EDIMasterPartner (06/10/2013)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIMasterPartner' and COLUMN_NAME='TransmissionID' and CHARACTER_MAXIMUM_LENGTH=15) = 1

BEGIN

  ALTER TABLE EDIMasterPartner ALTER COLUMN TransmissionID   CHAR(35)

  ALTER TABLE EDIMasterPartner ALTER COLUMN Qualifier        CHAR(4)

  ALTER TABLE EDIMasterPartner ALTER COLUMN PartnerId        CHAR(35)

  ALTER TABLE EDIMasterPartner ALTER COLUMN PartnerQualifier CHAR(4)

  ALTER TABLE EDIMasterPartner ALTER COLUMN Security         CHAR(14)

  ALTER TABLE EDIMasterPartner ADD   SyntaxId  CHAR(4)  NULL

  

    PRINT 'Change columns EDIMasterPartner (07/24/2016)'

END

GO



PRINT 'Checking table EDIMasterStation'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIMasterStation') = 1

BEGIN

  IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIMasterStation' AND COLUMN_NAME='AutoQtyPackType') = 0

  BEGIN

    ALTER TABLE EDIMasterStation ADD AutoQtyPackType char(6) NULL

    ALTER TABLE EDIMasterStation ADD AutoQtyPackName char(6) NULL

    ALTER TABLE EDIMasterStation ADD AutoQtyTareType char(6) NULL

    ALTER TABLE EDIMasterStation ADD AutoQtyTareName char(6) NULL

    PRINT 'Add new columns to EDIMasterStation  (03/01/2007)'

  END

  IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIMasterStation' AND COLUMN_NAME='DisplayImages') = 0

  BEGIN

    ALTER TABLE EDIMasterStation ADD DisplayImages char(1) NULL

    PRINT 'New column EDIMasterStation..DisplayImages'

  END

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIMasterStation') = 1

BEGIN

  IF ( SELECT COUNT(*) FROM EDIMasterStation ) > 0

   BEGIN

    PRINT '-----'

    PRINT 'Conversion required on Shipping Station Information'

    PRINT 'Contact support for assistance'

    PRINT '-----'

   END

  ELSE

   BEGIN

    DROP TABLE EDIMasterStation

    PRINT 'Drop table EDIMasterStation (12/11/2008)'

   END

END

GO



PRINT 'Checking table EDIMasterStations'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIMasterStations') = 0

BEGIN

    CREATE TABLE EDIMasterStations(

     Station                  CHAR(10)            NOT NULL,

     Information              CHAR(2000)          NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIMasterStationsKey PRIMARY KEY CLUSTERED

         (

          Station

         )

    )

    PRINT 'New table EDIMasterStations (02/04/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIMasterStations' and COLUMN_NAME='Information' and CHARACTER_MAXIMUM_LENGTH=2000) = 1

BEGIN

  ALTER TABLE EDIMasterStations ALTER COLUMN Information  CHAR(2900)

  ALTER TABLE EDIMasterStations ADD          InfoVersion  DECIMAL(3,0)

  

    PRINT 'Change columns EDIMasterStations (06/10/2013)'

END

GO



PRINT 'Checking table EDIMessages'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIMessages') = 0

BEGIN

    CREATE TABLE EDIMessages(

     System                   CHAR(10)            NOT NULL,

     Receipient               CHAR(20)            NOT NULL,

     EntryDate                DATETIME            NOT NULL,

     EntryTime                DECIMAL(8,0)        NOT NULL,

     Message                  CHAR(200)           NULL,

     State                    CHAR(1)             NULL,

     RcvDate                  DATETIME            NULL,

     RcvTime                  DECIMAL(8,0)        NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIMessagesKey PRIMARY KEY CLUSTERED

         (

          System,

          Receipient,

          EntryDate,

          EntryTime

         )

    )

    CREATE UNIQUE INDEX EDIMessagesIdxStatus ON EDIMessages(

     State,

     System,

     Receipient,

     EntryDate,

     EntryTime

     )

    PRINT 'New table EDIMessages'

END

GO



PRINT 'Checking table EDINext'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDINext') = 0

BEGIN

    CREATE TABLE EDINext(

     System                   CHAR(10)            NOT NULL,

     Type                     CHAR(50)            NOT NULL,

     LastDate                 DATETIME            NULL,

     NextValue                DECIMAL(15,0)       NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDINextKey PRIMARY KEY CLUSTERED

         (

          System,

          Type

         )

    )

    PRINT 'New table EDINext'

END



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDINext' and COLUMN_NAME='Type' and CHARACTER_MAXIMUM_LENGTH=10) = 1

BEGIN

  ALTER TABLE EDINext DROP CONSTRAINT EDINextKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDINext' and COLUMN_NAME='Type' and CHARACTER_MAXIMUM_LENGTH=10) = 1

BEGIN

  ALTER TABLE EDINext ALTER COLUMN Type      CHAR(50) NOT NULL

  ALTER TABLE EDINext ALTER COLUMN NextValue DECIMAL(15,0)

  

 ALTER TABLE EDINext

  ADD CONSTRAINT EDINextKey PRIMARY KEY CLUSTERED

  (

         System,

         Type

  )

    PRINT 'Change columns EDINext (06/10/2013)'

END

GO



EXEC dbo.CadacusNewColumn        '02/07/2022','N','EDINext','LastTime',8,0

EXEC dbo.CadacusNewColumn        '02/07/2022','C','EDINext','Detail',2000,0



PRINT 'Checking table EDINotes'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDINotes' and COLUMN_NAME='Text' and CHARACTER_MAXIMUM_LENGTH=60) = 1

BEGIN

  ALTER TABLE EDINotes ALTER COLUMN Text CHAR(100)

  

    PRINT 'Change columns EDINotes (06/10/2013)'

END

GO



PRINT 'Checking table EDIOrderIndex'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIXRefOrderIndex') = 1

BEGIN

  DROP TABLE EDIXRefOrderIndex

  PRINT 'Drop table EDIXRefOrderIndex (06/10/2013)'

END

GO



PRINT 'Checking table EDIPaymentComments'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIPaymentComments' AND COLUMN_NAME='Filler') = 1

BEGIN

  ALTER TABLE EDIPaymentComments DROP COLUMN Filler

  PRINT 'Modify table EDIPaymentComments (07/06/2009)'

END

GO



PRINT 'Checking table EDIPaymentDetail'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIPaymentDetail' AND COLUMN_NAME='OriginalDiscount') = 0

BEGIN

    ALTER TABLE EDIPaymentDetail ADD

     OriginalDiscount         DECIMAL(12,2)       NULL

    PRINT 'New column EDIPaymentDetail...OriginalDiscount (01/13/2009)'

END

GO





IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIPaymentDetail' AND COLUMN_NAME='UnappliedGroup') = 0

BEGIN

  ALTER TABLE EDIPaymentDetail ADD UnappliedGroup DECIMAL(5,0) NULL

  DECLARE @UPD NCHAR(100)

  SET @UPD=N'UPDATE EDIPaymentDetail SET UnappliedGroup=0'

  EXEC sp_executesql @UPD

  CREATE UNIQUE INDEX EDIPaymentDetailIdxGroup ON EDIPaymentDetail(

     Partner,

     CheckNumber,

     UnappliedGroup,

     Line

     )

  PRINT 'New column and index EDIPaymentDetail...UnappliedGroup (01/14/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIPaymentDetail' AND COLUMN_NAME='GroupCustomer') = 0

BEGIN

  ALTER TABLE EDIPaymentDetail ADD 

     GroupCustomer            CHAR(7)             NULL

  PRINT 'New column EDIPaymentDetail...GroupCustomer (01/18/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIPaymentDetail' AND COLUMN_NAME='BOFlag') = 0

BEGIN

    ALTER TABLE EDIPaymentDetail ADD

     BOFlag         CHAR(1)    NULL

    PRINT 'New column EDIPaymentDetail (01/10/2013)'

END

GO



IF (dbo.CadacusIndexTest('EDIPaymentDetailIdxInvoice') = 0)

BEGIN

  CREATE UNIQUE INDEX EDIPaymentDetailIdxInvoice ON EDIPaymentDetail(

   Partner,

   CheckNumber,

   Customer,

   Invoice,

   Cdi,

   Line

   )

  PRINT 'New index EDIPaymentDetail (01/24/2013)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIPaymentDetail' and COLUMN_NAME='Customer' and CHARACTER_MAXIMUM_LENGTH=7) = 1

BEGIN

  ALTER TABLE EDIPaymentDetail DROP CONSTRAINT EDIPaymentDetailKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIPaymentDetail' and COLUMN_NAME='Customer' and CHARACTER_MAXIMUM_LENGTH=7) = 1

BEGIN

  DROP INDEX EDIPaymentDetail.EDIPaymentDetailIdxGroup

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIPaymentDetail' and COLUMN_NAME='Customer' and CHARACTER_MAXIMUM_LENGTH=7) = 1

BEGIN

  DROP INDEX EDIPaymentDetail.EDIPaymentDetailIdxInvoice

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIPaymentDetail' and COLUMN_NAME='Customer' and CHARACTER_MAXIMUM_LENGTH=7) = 1

BEGIN

    ALTER TABLE EDIPaymentDetail ALTER COLUMN NetAmount        DECIMAL(14,2)

    ALTER TABLE EDIPaymentDetail ALTER COLUMN InvoiceAmount    DECIMAL(14,2)

    ALTER TABLE EDIPaymentDetail ALTER COLUMN Discount         DECIMAL(14,2)

    ALTER TABLE EDIPaymentDetail ALTER COLUMN Customer         CHAR(15)

    ALTER TABLE EDIPaymentDetail ALTER COLUMN Invoice          CHAR(20)

    ALTER TABLE EDIPaymentDetail ALTER COLUMN Balance          DECIMAL(14,2)

    ALTER TABLE EDIPaymentDetail ALTER COLUMN OrgAmount        DECIMAL(14,2)

    ALTER TABLE EDIPaymentDetail ALTER COLUMN InvoiceDate      DATETIME

    ALTER TABLE EDIPaymentDetail ALTER COLUMN Quantity         DECIMAL(18,6)

    ALTER TABLE EDIPaymentDetail ALTER COLUMN Price            DECIMAL(15,5)

    ALTER TABLE EDIPaymentDetail ALTER COLUMN GrossAmount      DECIMAL(14,2)

    ALTER TABLE EDIPaymentDetail ALTER COLUMN CalcDiscount     DECIMAL(14,2)

    ALTER TABLE EDIPaymentDetail ALTER COLUMN ShortOver        DECIMAL(14,2)

    ALTER TABLE EDIPaymentDetail ALTER COLUMN CreditMemos      DECIMAL(14,2)

    ALTER TABLE EDIPaymentDetail ALTER COLUMN DebitMemos       DECIMAL(14,2)

    ALTER TABLE EDIPaymentDetail ALTER COLUMN OriginalDiscount DECIMAL(14,2)

    ALTER TABLE EDIPaymentDetail ALTER COLUMN GroupCustomer    CHAR(15)

ALTER TABLE EDIPaymentDetail

  ADD CONSTRAINT EDIPaymentDetailKey PRIMARY KEY CLUSTERED

  (

         Partner,

         CheckNumber,

         Line

  )

CREATE UNIQUE INDEX EDIPaymentDetailIdxGroup ON EDIPaymentDetail(

 Partner,

 CheckNumber,

 UnappliedGroup,

 Line

 )

CREATE UNIQUE INDEX EDIPaymentDetailIdxInvoice ON EDIPaymentDetail(

 Partner,

 CheckNumber,

 Customer,

 Invoice,

 Cdi,

 Line

 )

    PRINT 'Change columns EDIPaymentDetail (06/10/2013)'

END

GO



PRINT 'Checking table EDIPaymentIndex'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIPaymentIndex' and COLUMN_NAME='Customer' and CHARACTER_MAXIMUM_LENGTH=7) = 1

BEGIN

  DELETE FROM EDIPaymentIndex

  ALTER TABLE EDIPaymentIndex DROP CONSTRAINT EDIPaymentIndexKey

  DROP INDEX EDIPaymentIndex.EDIPaymentIndexIdxBl

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIPaymentIndex' and COLUMN_NAME='Invoice' and CHARACTER_MAXIMUM_LENGTH=8) = 1

BEGIN

    ALTER TABLE EDIPaymentIndex ALTER COLUMN Invoice          CHAR(20) NOT NULL

    ALTER TABLE EDIPaymentIndex ALTER COLUMN Customer         CHAR(15) NOT NULL

    ALTER TABLE EDIPaymentIndex ALTER COLUMN TransactionDate  DATETIME

    ALTER TABLE EDIPaymentIndex ALTER COLUMN MemoInvoice      CHAR(20)



ALTER TABLE EDIPaymentIndex

  ADD CONSTRAINT EDIPaymentIndexKey PRIMARY KEY CLUSTERED

  (

         Flag,

         Invoice,

         Cdi,

         Customer

  )



CREATE UNIQUE INDEX EDIPaymentIndexIdxBl ON EDIPaymentIndex(

 BillOfLading,

 Invoice,

 Cdi,

 Customer

 )

    PRINT 'Change columns EDIPaymentIndex (06/10/2013)'

END

GO



PRINT 'Checking table EDIPaymentMaster'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIPaymentMaster' AND COLUMN_NAME='ImportGroup') = 0

BEGIN

    ALTER TABLE EDIPaymentMaster ADD

     ImportGroup              CHAR(14)            NULL,

     Sequence                 DECIMAL(5,0)        NULL

    PRINT 'New columns EDIPaymentMaster (07/20/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIPaymentMaster' and COLUMN_NAME='Operator' and CHARACTER_MAXIMUM_LENGTH=5) = 1

BEGIN

    ALTER TABLE EDIPaymentMaster ALTER COLUMN Operator         CHAR(20)

    ALTER TABLE EDIPaymentMaster ALTER COLUMN Amount           DECIMAL(14,2)

    ALTER TABLE EDIPaymentMaster ALTER COLUMN CheckDate        DATETIME

    ALTER TABLE EDIPaymentMaster ALTER COLUMN FirstJnl         DECIMAL(10,0)

    ALTER TABLE EDIPaymentMaster ALTER COLUMN LastJnl          DECIMAL(10,0)

    ALTER TABLE EDIPaymentMaster ALTER COLUMN Bank             CHAR(15)

    ALTER TABLE EDIPaymentMaster ALTER COLUMN Branch           CHAR(10)

    ALTER TABLE EDIPaymentMaster ALTER COLUMN Unmatched        DECIMAL(14,2)

    ALTER TABLE EDIPaymentMaster ALTER COLUMN CrdInvoice       CHAR(20)

    ALTER TABLE EDIPaymentMaster ALTER COLUMN ShortPay         DECIMAL(14,2)

    ALTER TABLE EDIPaymentMaster ALTER COLUMN OverPayment      DECIMAL(14,2)

    ALTER TABLE EDIPaymentMaster ALTER COLUMN Discount         DECIMAL(14,2)



    PRINT 'Change columns EDIPaymentMaster (06/10/2013)'

END

GO



EXEC dbo.CadacusNewColumn '09/24/2017','C','EDIPaymentMaster','Document',6,0



PRINT 'Checking table EDIPaymentStockDet'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIPaymentStockDet' AND COLUMN_NAME='Filler') = 1

BEGIN

  ALTER TABLE EDIPaymentStockDet DROP COLUMN Filler



  PRINT 'Modify table EDIPaymentStockDet (07/06/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIPaymentStockDet' and COLUMN_NAME='UnitOfMeasure' and CHARACTER_MAXIMUM_LENGTH=3) = 1

BEGIN

  ALTER TABLE EDIPaymentStockDet ALTER COLUMN Quantity      DECIMAL(18,6)

  ALTER TABLE EDIPaymentStockDet ALTER COLUMN Price         DECIMAL(17,5)

  ALTER TABLE EDIPaymentStockDet ALTER COLUMN UnitOfMeasure CHAR(10)

  

  PRINT 'Change columns EDIPaymentStockDet (06/10/2013)'

END

GO



PRINT 'Checking table EDIPreferences'

GO

IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIPreferences') = 0

BEGIN

    CREATE TABLE EDIPreferences(

     Operator                 CHAR(20)            NOT NULL,

     Code                     CHAR(10)            NOT NULL,

     Description              CHAR(60)            NOT NULL,

     InfoVersion              DECIMAL(3,0)        NULL,

     Information              CHAR(2900)          NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIPreferencesKey PRIMARY KEY CLUSTERED

         (

          Operator,

          Code,

          Description

         )

    )

    PRINT 'New table EDIPreferences (05/06/2010)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIPreferences' and COLUMN_NAME='RecordInfo') = 1

BEGIN

  IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIPreferences' and COLUMN_NAME='Information') = 0

   BEGIN

    EXEC sp_rename 'EDIPreferences.RecordInfo',      'Information',      'COLUMN';

    PRINT 'Correct EDIPreferences.RecordInfo error (09/19/2017)'

   END

  ELSE

   BEGIN

    ALTER TABLE EDIPreferences DROP COLUMN RecordInfo

    PRINT 'Correct EDIPreferences.RecordInfo error (09/19/2017)'

   END

END

GO



EXEC dbo.CadacusDropPrimaryKey 'EDIPreferences','Operator',20

EXEC dbo.CadacusDropPrimaryKey 'EDIPreferences','Code',20



EXEC dbo.CadacusAlterColumn  '06/10/2013','C','EDIPreferences','Operator',20,0

EXEC dbo.CadacusAlterColumn  '06/10/2013','C','EDIPreferences','Description',60,0

EXEC dbo.CadacusNewColumn    '06/10/2013','N','EDIPreferences','InfoVersion',3,0

EXEC dbo.CadacusAlterColumn  '04/12/2020','C','EDIPreferences','Code',20,0

EXEC dbo.CadacusAlterColumn  '04/12/2020','C','EDIPreferences','Information',2500,0

EXEC dbo.CadacusNewColumn    '04/12/2020','C','EDIPreferences','PreferenceFile',300,0



EXEC dbo.CadacusAddPrimaryKey 'EDIPreferences','Operator, Code'





--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIPreferences' and COLUMN_NAME='Operator' and CHARACTER_MAXIMUM_LENGTH=6) = 1

--BEGIN

--  ALTER TABLE EDIPreferences DROP CONSTRAINT EDIPreferencesKey

--END

--GO



--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIPreferences' and COLUMN_NAME='Operator' and CHARACTER_MAXIMUM_LENGTH=6) = 1

--BEGIN

--  ALTER TABLE EDIPreferences ALTER COLUMN Operator    CHAR(20) NOT NULL

--  ALTER TABLE EDIPreferences ALTER COLUMN Description CHAR(60) NOT NULL

--  ALTER TABLE EDIPreferences ADD          InfoVersion DECIMAL(3,0)

--  ALTER TABLE EDIPreferences

--    ADD CONSTRAINT EDIPreferencesKey PRIMARY KEY CLUSTERED

--    (

--         Operator,

--         Code,

--         Description

--    )

--  PRINT 'Change columns EDIPreferences (06/10/2013)'

--END

--GO





PRINT 'Checking table EDIPkgInterface'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIPkgInterface' and COLUMN_NAME='SalesOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  ALTER TABLE EDIPkgInterface ALTER COLUMN SalesOrder    CHAR(20)

  ALTER TABLE EDIPkgInterface ALTER COLUMN PurchaseOrder CHAR(30)

  ALTER TABLE EDIPkgInterface ALTER COLUMN Customer      CHAR(15)

  ALTER TABLE EDIPkgInterface ALTER COLUMN Carrier       CHAR(50)

  ALTER TABLE EDIPkgInterface ALTER COLUMN CODAmount     DECIMAL(14,2)

  ALTER TABLE EDIPkgInterface ALTER COLUMN PackageValue  DECIMAL(14,2)



  PRINT 'Change columns EDIPkgInterface (06/10/2013)'

END

GO



PRINT 'Checking table EDIReceiverItem'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIReceiverItem' and COLUMN_NAME='PurchaseOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  ALTER TABLE EDIReceiverItem DROP CONSTRAINT EDIReceiverItemKey

  DROP INDEX EDIReceiverItem.EDIReceiverItemIdxStock

  DROP INDEX EDIReceiverItem.EDIReceiverItemIdxReceiver

  DROP INDEX EDIReceiverItem.EDIReceiverItemIdxLine

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIReceiverItem' and COLUMN_NAME='PurchaseOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  ALTER TABLE EDIReceiverItem ALTER COLUMN PurchaseOrder CHAR(20)

  ALTER TABLE EDIReceiverItem ALTER COLUMN Quantity      DECIMAL(18,6)

  ALTER TABLE EDIReceiverItem ALTER COLUMN OrderQuantity DECIMAL(18,6)

  ALTER TABLE EDIReceiverItem ALTER COLUMN CaseQuantity  DECIMAL(12,0)

  ALTER TABLE EDIReceiverItem ALTER COLUMN InnerQuantity DECIMAL(12,0)

  ALTER TABLE EDIReceiverItem ALTER COLUMN Serial        CHAR(50)

  ALTER TABLE EDIReceiverItem ALTER COLUMN Lot           CHAR(50)

  ALTER TABLE EDIReceiverItem ALTER COLUMN Bin           CHAR(20)



ALTER TABLE EDIReceiverItem

  ADD CONSTRAINT EDIReceiverItemKey PRIMARY KEY CLUSTERED

  (

         Receiver,

         ItemNumber

  )



CREATE UNIQUE INDEX EDIReceiverItemIdxStock ON EDIReceiverItem(

 StockCode,

 Receiver,

 ItemNumber

 )



CREATE UNIQUE INDEX EDIReceiverItemIdxReceiver ON EDIReceiverItem(

 Receiver,

 Tare,

 Pack,

 ItemNumber

 )



CREATE UNIQUE INDEX EDIReceiverItemIdxLine ON EDIReceiverItem(

 Receiver,

 PurchaseOrder,

 OrderLine,

 ItemNumber

 )



  PRINT 'Change columns EDIReceiverItem (06/10/2013)'

END

GO



PRINT 'Checking table EDIReceiverOrder'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIReceiverOrder' and COLUMN_NAME='PurchaseOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  ALTER TABLE EDIReceiverOrder DROP CONSTRAINT EDIReceiverOrderKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIReceiverOrder' and COLUMN_NAME='PurchaseOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  ALTER TABLE EDIReceiverOrder ALTER COLUMN PurchaseOrder  CHAR(20) NOT NULL

  ALTER TABLE EDIReceiverOrder ALTER COLUMN Vendor         CHAR(15) NOT NULL

    

  ALTER TABLE EDIReceiverOrder

    ADD CONSTRAINT EDIReceiverOrderKey PRIMARY KEY CLUSTERED

         (

          Receiver,

          PurchaseOrder

         )

  PRINT 'Change columns EDIReceiverOrder (01/07/2015)'

END

GO



PRINT 'Checking table EDIReceiverPack'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIReceiverPack' AND COLUMN_NAME='Lenght') = 1

BEGIN

    EXEC sp_rename 'EDIReceiverPack.Lenght',      'Length',      'COLUMN';

    PRINT 'Rename column EDIReceiverPack  (06/19/2012)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIReceiverPack' and COLUMN_NAME='PackWeight' and NUMERIC_SCALE=0) = 1

BEGIN

  ALTER TABLE EDIReceiverPack ALTER COLUMN MerchandiseValue DECIMAL(14,2)

  ALTER TABLE EDIReceiverPack ALTER COLUMN MiscValue        DECIMAL(14,2)

  ALTER TABLE EDIReceiverPack ALTER COLUMN PackWeight       DECIMAL(18,6)

  ALTER TABLE EDIReceiverPack ALTER COLUMN FreightCost      DECIMAL(14,2)

  ALTER TABLE EDIReceiverPack ALTER COLUMN FreightCharge    DECIMAL(14,2)



    PRINT 'Change columns EDIReceiverPack (06/10/2013)'

END

GO



PRINT 'Checking table EDIReceiverMaster'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIReceiverMaster' AND COLUMN_NAME='YearPost') = 0

BEGIN

    ALTER TABLE EDIReceiverMaster ADD YearPost decimal(4,0) NULL

    ALTER TABLE EDIReceiverMaster ADD MonthPost decimal(2,0) NULL

    ALTER TABLE EDIReceiverMaster ADD Journal decimal(5,0) NULL

    PRINT 'Add new receiving columns to EDIReceiverMaster'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIReceiverMaster' AND COLUMN_NAME='Unit') = 0

BEGIN

    ALTER TABLE EDIReceiverMaster ADD Unit char(20) NULL

    PRINT 'New column EDIReceiverMaster..Unit (02/29/2008)'

END





IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIReceiverMaster' and COLUMN_NAME='Employee' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  ALTER TABLE EDIReceiverMaster DROP CONSTRAINT EDIReceiverMasterKey

  DROP INDEX EDIReceiverMaster.EDIReceiverMasterIdxBol

  DROP INDEX EDIReceiverMaster.EDIReceiverMasterIdxPro

  UPDATE EDIReceiverMaster SET Journal='0' WHERE Journal < '0'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIReceiverMaster' and COLUMN_NAME='Employee' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  ALTER TABLE EDIReceiverMaster ALTER COLUMN Employee      CHAR(20)

  ALTER TABLE EDIReceiverMaster ALTER COLUMN BOLNumber     CHAR(50)

  ALTER TABLE EDIReceiverMaster ALTER COLUMN ProNumber     CHAR(50)

  ALTER TABLE EDIReceiverMaster ALTER COLUMN TrailerNumber CHAR(50)

  ALTER TABLE EDIReceiverMaster ALTER COLUMN Appointment   CHAR(50)

  ALTER TABLE EDIReceiverMaster ALTER COLUMN LoadNumber    CHAR(50)

  ALTER TABLE EDIReceiverMaster ALTER COLUMN Seal          CHAR(50)

  ALTER TABLE EDIReceiverMaster ALTER COLUMN User1         CHAR(50)

  ALTER TABLE EDIReceiverMaster ALTER COLUMN User2         CHAR(50)

  ALTER TABLE EDIReceiverMaster ALTER COLUMN Journal       DECIMAL(10,0)



ALTER TABLE EDIReceiverMaster

  ADD CONSTRAINT EDIReceiverMasterKey PRIMARY KEY CLUSTERED

  (

         ReceiverNumber

  )



CREATE UNIQUE INDEX EDIReceiverMasterIdxBol ON EDIReceiverMaster(

 BOLNumber,

 ReceiverNumber

 )



CREATE UNIQUE INDEX EDIReceiverMasterIdxPro ON EDIReceiverMaster(

 ProNumber,

 ReceiverNumber

 )

  PRINT 'Change columns EDIReceiverMaster (06/10/2013)'

END

GO



PRINT 'Checking table EDIRelease'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIRelease' and COLUMN_NAME='ReleaseDate' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

    ALTER TABLE EDIRelease ALTER COLUMN ReleaseDate CHAR(8)



  DECLARE @UPD NCHAR(200)

  SET @UPD=N'Update EDIRelease SET ReleaseDate=''20''+SUBSTRING(ReleaseDate,5,2)+SUBSTRING(ReleaseDate,1,4) WHERE ReleaseDate>''00000000'' AND ReleaseDate<''19000101'''

  EXEC sp_executesql @UPD

  SET @UPD=N'Update EDIRelease SET ReleaseDate=''19000101'' WHERE ReleaseDate<''19000101'''

  EXEC sp_executesql @UPD



    --Update EDIRelease SET ReleaseDate='20'+SUBSTRING(ReleaseDate,5,2)+SUBSTRING(ReleaseDate,1,4) WHERE ReleaseDate>'00000000' AND ReleaseDate<'19000101'

    --Update EDIRelease SET ReleaseDate='19000101' WHERE ReleaseDate<'19000101'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIRelease' and COLUMN_NAME='Operator' and CHARACTER_MAXIMUM_LENGTH=5) = 1

BEGIN

  ALTER TABLE EDIRelease ALTER COLUMN SalesOrder  CHAR(20)

  ALTER TABLE EDIRelease ALTER COLUMN Invoice     CHAR(20)

  ALTER TABLE EDIRelease ALTER COLUMN Operator    CHAR(20)

  ALTER TABLE EDIRelease ALTER COLUMN ReleaseDate DATETIME

END

GO



PRINT 'Checking table EDIReplenishment'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIXRefReplenishment') = 1

BEGIN

  DROP TABLE EDIXRefReplenishment

  PRINT 'Drop table EDIXRefReplenishment (06/10/2013)'

END

GO



PRINT 'Checking table EDIReportDetail'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIReportDetail') = 0

BEGIN

    CREATE TABLE EDIReportDetail(

     Report                   DECIMAL(9,0)        NOT NULL,

     Line                     DECIMAL(9,0)        NOT NULL,

     LineType                 CHAR(1)             NULL,

     Message                  CHAR(200)           NULL,

     Number                   DECIMAL(9,0)        NULL,

     Info1                    CHAR(50)            NULL,

     Info2                    CHAR(50)            NULL,

     Info3                    CHAR(50)            NULL,

     Info4                    CHAR(50)            NULL,

     Info5                    CHAR(50)            NULL,

     Info6                    CHAR(50)            NULL,

     Info7                    CHAR(50)            NULL,

     Info8                    CHAR(50)            NULL,

     Info9                    CHAR(50)            NULL,

     Value1                   DECIMAL(18,6)       NULL,

     Value2                   DECIMAL(18,6)       NULL,

     Value3                   DECIMAL(18,6)       NULL,

     Value4                   DECIMAL(18,6)       NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIReportDetailKey PRIMARY KEY CLUSTERED

         (

          Report,

          Line

         )

    )

    PRINT 'New table EDIReportDetail'

END

GO



EXEC dbo.CadacusNewColumn '08/24/2022','D','EDIReportDetail','Date1',0,0

EXEC dbo.CadacusNewColumn '08/24/2022','D','EDIReportDetail','Date2',0,0

EXEC dbo.CadacusNewColumn '08/24/2022','D','EDIReportDetail','Date3',0,0



PRINT 'Checking table EDIReportHeader'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIReportHeader') = 0

BEGIN

    CREATE TABLE EDIReportHeader(

     Report                   DECIMAL(9,0)        NOT NULL,

     LastLine                 DECIMAL(9,0)        NULL,

     ReportDate               DATETIME            NULL,

     ReportTime               DECIMAL(8,0)        NULL,

     Program                  CHAR(6)             NULL,

     Operator                 CHAR(20)            NULL,

     ReverseDate              DECIMAL(9,0)        NULL,

     ReverseTime              DECIMAL(8,0)        NULL,

     Partner                  CHAR(10)            NULL,

     Document                 CHAR(6)             NULL,

     ImportExport             CHAR(1)             NULL,

     Archive                  CHAR(300)           NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIReportHeaderKey PRIMARY KEY CLUSTERED

         (

          Report

         )

    )

    PRINT 'New table EDIReportHeader'

END

GO



EXEC dbo.CadacusNewColumn '03/09/2022','N','EDIReportHeader','Errors',9,0

EXEC dbo.CadacusNewColumn '03/09/2022','N','EDIReportHeader','Warnings',9,0



PRINT 'Checking table EDIShipmentAdd'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentAdd' and COLUMN_NAME='SalesOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  ALTER TABLE EDIShipmentAdd DROP CONSTRAINT EDIShipmentAddKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentAdd' and COLUMN_NAME='SalesOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

    ALTER TABLE EDIShipmentAdd ALTER COLUMN SalesOrder CHAR(20) NOT NULL

    ALTER TABLE EDIShipmentAdd ALTER COLUMN Contact    CHAR(50)    

    ALTER TABLE EDIShipmentAdd

     ADD CONSTRAINT EDIShipmentAddKey PRIMARY KEY CLUSTERED

      (

         Shipment,

         SalesOrder,

         Number

      )

    PRINT 'Change columns EDIShipmentAdd (06/10/2013)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentAdd' and COLUMN_NAME='State' and CHARACTER_MAXIMUM_LENGTH=2) = 1

BEGIN

    ALTER TABLE EDIShipmentAdd ALTER COLUMN State CHAR(20)

    PRINT 'Change column EDIShipmentAdd (10/12/2015)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentAdd' and COLUMN_NAME='Line7') = 0

BEGIN

    EXEC sp_rename 'EDIShipmentAdd.Line6',      'Line7',      'COLUMN';

    PRINT 'Rename column EDIShipmentAdd..Line6 to Line7 (12/08/2020)'

END

GO



EXEC dbo.CadacusNewColumn '12/08/2020','C','EDIShipmentAdd','EMail',50,0

EXEC dbo.CadacusNewColumn '12/08/2020','C','EDIShipmentAdd','Line6',50,0

EXEC dbo.CadacusNewColumn '11/03/2021','N','EDIShipmentAdd','Document',9,0

EXEC dbo.CadacusNewColumn '11/03/2021','C','EDIShipmentAdd','DispatchNote',20,0



PRINT 'Checking table EDIShipmentFedex'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIShipmentFedex') = 0

BEGIN

    CREATE TABLE EDIShipmentFedex(

     TrackingNumber           CHAR(30)            NOT NULL,

     Info                     CHAR(2900)          NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIShipmentFedexKey PRIMARY KEY CLUSTERED

         (

          TrackingNumber

         )

    )

    PRINT 'New table EDIShipmentFedex (05/11/2011)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentFedex' AND COLUMN_NAME='InfoVersion') = 0

BEGIN

  ALTER TABLE EDIShipmentFedex ADD          InfoVersion  DECIMAL(3,0)

  

    PRINT 'Change columns EDIShipmentFedex (06/10/2013)'

END

GO



EXEC dbo.CadacusAlterColumn '07/11/2019','C','EDIShipmentFedex','Info',3900,0



PRINT 'Checking table EDIShipmentItem'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentItem' AND COLUMN_NAME='TarePackLevel') = 0

BEGIN

    ALTER TABLE EDIShipmentItem ADD 

     TarePackLevel           CHAR(1)            NULL

    PRINT 'Add new column to EDIShipmentItem  (08/27/2010)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentItem' AND COLUMN_NAME='NMFCItem') = 0

BEGIN

    ALTER TABLE EDIShipmentItem ADD 

     NMFCItem                 CHAR(20)            NULL,

     NMFCClass                CHAR(10)            NULL,

     ItemValue                DECIMAL(10,3)       NULL

    PRINT 'Add new columns to EDIShipmentItem  (12/19/2010)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentItem' and COLUMN_NAME='SalesOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

    ALTER TABLE EDIShipmentItem ALTER COLUMN SalesOrder     CHAR(20)

    ALTER TABLE EDIShipmentItem ALTER COLUMN DispatchNote   CHAR(20)

    ALTER TABLE EDIShipmentItem ALTER COLUMN Quantity       DECIMAL(18,6)

    ALTER TABLE EDIShipmentItem ALTER COLUMN OrderQuantity  DECIMAL(18,6)

    ALTER TABLE EDIShipmentItem ALTER COLUMN CaseQuantity   DECIMAL(12,0)

    ALTER TABLE EDIShipmentItem ALTER COLUMN InnerQuantity  DECIMAL(12,0)

    ALTER TABLE EDIShipmentItem ALTER COLUMN Serial         CHAR(50)

    ALTER TABLE EDIShipmentItem ALTER COLUMN Lot            CHAR(50)

    ALTER TABLE EDIShipmentItem ALTER COLUMN Bin            CHAR(20)

    ALTER TABLE EDIShipmentItem ALTER COLUMN ItemValue      DECIMAL(18,6)

    PRINT 'Change columns EDIShipmentItem (06/10/2013)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentItem' AND COLUMN_NAME='VerifiedQuantity') = 0

BEGIN

    ALTER TABLE EDIShipmentItem ADD 

     VerifiedQuantity         DECIMAL(18,6)       NULL,

     QuantityOrderUOM         DECIMAL(18,6)       NULL,

     StockingUOM              CHAR(10)            NULL,

     OrderUOM                 CHAR(10)            NULL

    PRINT 'Add new columns to EDIShipmentItem  (02/18/2014)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentItem' AND COLUMN_NAME='Weight') = 0

BEGIN

    ALTER TABLE EDIShipmentItem ADD 

     Weight        DECIMAL(18,6)       NULL

    PRINT 'Add new columns to EDIShipmentItem  (10/20/2015)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentItem' AND COLUMN_NAME='DGCode') = 0

BEGIN

    ALTER TABLE EDIShipmentItem ADD 

     DGCode                   CHAR(30)            NULL,

     DGQuantity               DECIMAL(18,6)       NULL,

     DGUnits                  CHAR(10)            NULL

    PRINT 'Add new columns to EDIShipmentItem  (8/2/2016)'

END

GO



EXEC dbo.CadacusNewColumn '02/23/2017','C','EDIShipmentItem','LicensePlate',50,0

EXEC dbo.CadacusDropIndex 'EDIShipmentItem', 'SalesOrder', 'Dummy',1    -- Remove index created incorrectly before release

EXEC dbo.CadacusAddIndex  'EDIShipmentItem', 'Order', 'Shipment, SalesOrder, Tare, Pack, ItemNumber'

EXEC dbo.CadacusNewColumn '03/31/2021','C','EDIShipmentItem','Warehouse',10,0

EXEC dbo.CadacusNewColumn '11/03/2021','N','EDIShipmentItem','Document',9,0

EXEC dbo.CadacusNewColumn '06/27/2022','D','EDIShipmentItem','LotExpiryDate',0,0



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

	    WHERE TABLE_NAME='EDIShipmentItem' AND COLUMN_NAME='Item') = 0

BEGIN

  EXEC dbo.CadacusDropPrimaryKey 'EDIShipmentItem','X',1

  EXEC dbo.CadacusDropIndex      'EDIShipmentItem','Stock','X',1

  EXEC dbo.CadacusDropIndex      'EDIShipmentItem','Shipment','X',1

  EXEC dbo.CadacusDropIndex      'EDIShipmentItem','Order','X',1

  EXEC dbo.CadacusRenameColumn   '11/03/2021','EDIShipmentItem','ItemNumber','Item','Y'

  EXEC dbo.CadacusRenameColumn   '11/03/2021','EDIShipmentItem','TarePackLevel','LevelCode','Y'

  EXEC dbo.CadacusAddPrimaryKey  'EDIShipmentItem','Shipment, Item'

  EXEC dbo.CadacusAddIndex       'EDIShipmentItem', 'Stock', 'StockCode,Shipment,Item'

  EXEC dbo.CadacusAddIndex       'EDIShipmentItem', 'Shipment', 'Shipment,Tare,Pack,Item'

  EXEC dbo.CadacusAddIndex       'EDIShipmentItem', 'Order', 'Shipment,SalesOrder,Tare,Pack,Item'

END

GO



PRINT 'Checking table EDIShipmentDHLMan'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIShipmentDHLMan') = 1

BEGIN

  DROP TABLE EDIShipmentDHLMan

  PRINT 'Drop table EDIShipmentDHLMan (06/10/2013)'

END

GO



PRINT 'Checking table EDIShipmentDHLPce'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIShipmentDHLPce') = 1

BEGIN

  DROP TABLE EDIShipmentDHLPce

  PRINT 'Drop table EDIShipmentDHLPce (06/10/2013)'

END

GO



PRINT 'Checking table EDIShipmentDHLShp'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIShipmentDHLShp') = 1

BEGIN

  DROP TABLE EDIShipmentDHLShp

  PRINT 'Drop table EDIShipmentDHLShp (06/10/2013)'

END

GO



PRINT 'Checking table EDIShipmentLevel'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIShipmentLevel') = 0

BEGIN

    CREATE TABLE EDIShipmentLevel(

     ShipmentNumber           DECIMAL(9,0)        NOT NULL,

     LevelCode                CHAR(1)             NOT NULL,

     Status                   CHAR(1)             NULL,

     Employee                 CHAR(20)            NULL,

     Station                  CHAR(10)            NULL,

     TareCount                DECIMAL(9,0)        NULL,

     PackCount                DECIMAL(9,0)        NULL,

     ItemCount                DECIMAL(9,0)        NULL,

     TimeMark                 CHAR(16)            NULL,

     ActualTareCount          DECIMAL(9,0)        NULL,

     ActualPackCount          DECIMAL(9,0)        NULL,

     TareCountFlag            CHAR(1)             NULL,

     PackCountFlag            CHAR(1)             NULL,

     TareStatus               CHAR(1)             NULL,

     PackStatus               CHAR(1)             NULL,

     StatusDate               DATETIME            NULL,

     StatusTime               CHAR(6)             NULL,

     Handheld                 CHAR(20)            NULL,

     HandheldEmp              CHAR(20)            NULL,

     ExportDate               DATETIME            NULL,

     ExportTime               DECIMAL(8,0)        NULL,

     ImportDate               DATETIME            NULL,

     ImportTime               DECIMAL(8,0)        NULL,

     SaveDate                 DATETIME            NULL,

     SaveTime                 DECIMAL(8,0)        NULL,

     SaveElapsed              DECIMAL(9,0)        NULL,

     Archive                  CHAR(200)           NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIShipmentLevelKey PRIMARY KEY CLUSTERED

         (

          ShipmentNumber,

          LevelCode

         )

    )

    PRINT 'New table EDIShipmentLevel'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

	    WHERE TABLE_NAME='EDIShipmentLevel' AND COLUMN_NAME='Shipment') = 0

BEGIN

  EXEC dbo.CadacusDropPrimaryKey 'EDIShipmentLevel','X',1

  EXEC dbo.CadacusRenameColumn   '11/03/2021','EDIShipmentLevel','ShipmentNumber','Shipment','Y'

  EXEC dbo.CadacusAddPrimaryKey  'EDIShipmentLevel','Shipment, LevelCode'

END

GO



PRINT 'Checking table EDIShipmentLock'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentLock' AND COLUMN_NAME='Handheld') = 0

BEGIN

    ALTER TABLE EDIShipmentLock ADD 

     Handheld                 CHAR(20)            NULL

    PRINT 'Add new column to EDIShipmentLock  (05/01/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentLock' AND COLUMN_NAME='LockDate') = 0

BEGIN

    ALTER TABLE EDIShipmentLock ADD 

     LockDate                 DATETIME            NULL,

     LockTime                 DECIMAL(8,0)        NULL

    PRINT 'Add new columns to EDIShipmentLock  (01/28/2010)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentLock' and COLUMN_NAME='LockCode' and CHARACTER_MAXIMUM_LENGTH=15) = 1

BEGIN

  ALTER TABLE EDIShipmentLock DROP CONSTRAINT EDIShipmentLockKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentLock' and COLUMN_NAME='LockCode' and CHARACTER_MAXIMUM_LENGTH=15) = 1

BEGIN

    ALTER TABLE EDIShipmentLock ALTER COLUMN LockCode CHAR(20) NOT NULL

    ALTER TABLE EDIShipmentLock ADD          Operator CHAR(20)



 ALTER TABLE EDIShipmentLock

  ADD CONSTRAINT EDIShipmentLockKey PRIMARY KEY CLUSTERED

  (

         LockCode

  )

   PRINT 'Change columns EDIShipmentLock (06/10/2013)'

END

GO



PRINT 'Checking table EDIShipmentMaster'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentMaster' AND COLUMN_NAME='ChargeCode') = 0

BEGIN

    ALTER TABLE EDIShipmentMaster ADD ChargeCode char(8) NULL

    PRINT 'New column EDIShipmentMaster..ChargeCode'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentMaster' AND COLUMN_NAME='StatusDate') = 0

BEGIN

    ALTER TABLE EDIShipmentMaster ADD StatusDate datetime NULL

    ALTER TABLE EDIShipmentMaster ADD StatusTime char(6)  NULL

    ALTER TABLE EDIShipmentMaster ADD Reconciled char(1)  NULL

    PRINT 'Add new columns to EDIShipmentMaster (03/06/2007)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentMaster' AND COLUMN_NAME='Unit') = 0

BEGIN

    ALTER TABLE EDIShipmentMaster ADD Unit char(20) NULL

    PRINT 'New column EDIShipmentMaster..Unit (02/29/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentMaster' AND COLUMN_NAME='LastStation') = 0

BEGIN

    ALTER TABLE EDIShipmentMaster ADD LastStation char(10) NULL

    PRINT 'New column EDIShipmentMaster..LastStation (09/19/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentMaster' AND COLUMN_NAME='Volume') = 0

BEGIN

    ALTER TABLE EDIShipmentMaster ADD Volume Decimal(7,0) NULL

    PRINT 'New column EDIShipmentMaster..Volume (07/08/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentMaster' AND COLUMN_NAME='ImportHandheld') = 1

BEGIN

    EXEC sp_rename 'EDIShipmentMaster.ImportHandheld',      'Handheld',      'COLUMN';

    PRINT 'Rename column EDIShipmentMaster..ImportHandheld (05/12/2010)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentMaster' AND COLUMN_NAME='Handheld') = 0

BEGIN

    ALTER TABLE EDIShipmentMaster ADD 

     Handheld           CHAR(20)            NULL

    PRINT 'New column EDIShipmentMaster..Handheld (11/16/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentMaster' AND COLUMN_NAME='NMFCClass') = 0

BEGIN

    ALTER TABLE EDIShipmentMaster ADD 

     NMFCClass                CHAR(10)            NULL

    PRINT 'New column EDIShipmentMaster..NMFCClass (03/02/2010)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentMaster' AND COLUMN_NAME='HandheldEmp') = 0

BEGIN

    ALTER TABLE EDIShipmentMaster ADD 

     HandheldEmp              CHAR(6)             NULL,

     ExportDate               DATETIME            NULL,

     ExportTime               DECIMAL(8,0)        NULL,

     ImportDate               DATETIME            NULL,

     ImportTime               DECIMAL(8,0)        NULL,

     SaveDate                 DATETIME            NULL,

     SaveTime                 DECIMAL(8,0)        NULL,

     SaveElapsed              DECIMAL(9,0)        NULL

    PRINT 'New columns EDIShipmentMaster (05/12/2010)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentMaster' AND COLUMN_NAME='Splits') = 0

BEGIN

    ALTER TABLE EDIShipmentMaster ADD 

     Splits                   DECIMAL(4,0)        NULL,

     ActiveSplits             DECIMAL(4,0)        NULL

    PRINT 'New columns EDIShipmentMaster (01/18/2012)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentMaster' and COLUMN_NAME='Employee' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  DROP INDEX EDIShipmentMaster.EDIShipmentMasterIdxBol

  DROP INDEX EDIShipmentMaster.EDIShipmentMasterIdxPro

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentMaster' and COLUMN_NAME='Employee' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

    ALTER TABLE EDIShipmentMaster ALTER COLUMN Employee       CHAR(20)

    ALTER TABLE EDIShipmentMaster ADD          ShipViaCode    CHAR(6)

    ALTER TABLE EDIShipmentMaster ALTER COLUMN ShipVia        CHAR(50)

    ALTER TABLE EDIShipmentMaster ALTER COLUMN BOLNumber      CHAR(50)

    ALTER TABLE EDIShipmentMaster ALTER COLUMN ProNumber      CHAR(50)

    ALTER TABLE EDIShipmentMaster ALTER COLUMN TrailerNumber  CHAR(50)

    ALTER TABLE EDIShipmentMaster ALTER COLUMN Appointment    CHAR(50)

    ALTER TABLE EDIShipmentMaster ALTER COLUMN Seal           CHAR(50)

    ALTER TABLE EDIShipmentMaster ALTER COLUMN LoadNumber     CHAR(50)

    ALTER TABLE EDIShipmentMaster ALTER COLUMN User1          CHAR(50)

    ALTER TABLE EDIShipmentMaster ALTER COLUMN User2          CHAR(50)

    ALTER TABLE EDIShipmentMaster ALTER COLUMN ImportEmployee CHAR(20)

    ALTER TABLE EDIShipmentMaster ALTER COLUMN HandheldEmp    CHAR(20)

    ALTER TABLE EDIShipmentMaster ALTER COLUMN FreightCost    DECIMAL(14,2)

    ALTER TABLE EDIShipmentMaster ALTER COLUMN FreightCharge  DECIMAL(14,2)

    

  CREATE UNIQUE INDEX EDIShipmentMasterIdxBol ON EDIShipmentMaster(

   BOLNumber,

   ShipmentNumber

   )

  CREATE UNIQUE INDEX EDIShipmentMasterIdxPro ON EDIShipmentMaster(

   ProNumber,

   ShipmentNumber

   )

   PRINT 'Change columns EDIShipmentMaster (06/10/2013)'

END

GO





IF (dbo.CadacusIndexTest('EDIShipmentMasterIdxStatus') = 0)

BEGIN

    CREATE UNIQUE INDEX EDIShipmentMasterIdxStatus ON EDIShipmentMaster(

     Status,

     ShipmentNumber

     )

  PRINT 'Adding Index EDIShipmentMaster (02/04/2011)'

END

GO



IF (dbo.CadacusIndexTest('EDIShipmentMasterIdxScac') = 0)

BEGIN

     CREATE UNIQUE INDEX EDIShipmentMasterIdxScac ON EDIShipmentMaster(

      SCACInformation,

      ShipDate,

      Status,

      ShipmentNumber

      )

  PRINT 'Adding Index EDIShipmentMaster (03/10/2012)'

END

GO



EXEC dbo.CadacusNewColumn   '05/14/2014','C','EDIShipmentMaster','Archive',200,0

EXEC dbo.CadacusNewColumn   '12/15/2014','C','EDIShipmentMaster','CarrierService',10,0

EXEC dbo.CadacusNewColumn   '04/20/2018','C','EDIShipmentMaster','LastLevel',1,0

EXEC dbo.CadacusAlterColumn '09/04/2018','C','EDIShipmentMaster','ChargeCode',20,0

EXEC dbo.CadacusNewColumn   '02/25/2019','N','EDIShipmentMaster','FreightActual',9,2

EXEC dbo.CadacusAlterColumn '03/02/2022','N','EDIShipmentMaster','Weight',18,6



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

	    WHERE TABLE_NAME='EDIShipmentMaster' AND COLUMN_NAME='Shipment') = 0

BEGIN

  EXEC dbo.CadacusDropPrimaryKey 'EDIShipmentMaster','X',1

  EXEC dbo.CadacusRenameColumn   '11/03/2021','EDIShipmentMaster','ShipmentNumber','Shipment','Y'

  EXEC dbo.CadacusAddPrimaryKey  'EDIShipmentMaster','Shipment'

END

GO



EXEC dbo.CadacusNewColumn '11/03/2021','N','EDIShipmentMaster','DocumentCount',9,0



PRINT 'Checking table EDIShipmentMasterD'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentMasterD' and COLUMN_NAME='Operator' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

    ALTER TABLE EDIShipmentMasterD ALTER COLUMN MasterDate   DATETIME

    ALTER TABLE EDIShipmentMasterD ALTER COLUMN Operator     CHAR(20)

    ALTER TABLE EDIShipmentMasterD ALTER COLUMN ShipToCode   CHAR(15)

    ALTER TABLE EDIShipmentMasterD ALTER COLUMN ShipToMult   CHAR(20)

    ALTER TABLE EDIShipmentMasterD ALTER COLUMN BillToCode   CHAR(15)

    ALTER TABLE EDIShipmentMasterD ALTER COLUMN BillToMult   CHAR(20)



   PRINT 'Change columns EDIShipmentMasterD (06/10/2013)'

END

GO



PRINT 'Checking table EDIShipmentOrder'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentOrder' AND COLUMN_NAME='Department') = 0

BEGIN

    ALTER TABLE EDIShipmentOrder ADD Department char(10) NULL

    ALTER TABLE EDIShipmentOrder ADD Type char(20) NULL

    PRINT 'New columns EDIShipmentOrder..Department and Type (02/13/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentOrder' AND COLUMN_NAME='ShipValue') = 0

BEGIN

    ALTER TABLE EDIShipmentOrder ADD 

    	ShipValue                DECIMAL(9,2)        NULL

    PRINT 'New column EDIShipmentOrder (08/27/2010)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentOrder' AND COLUMN_NAME='OrderValue') = 0

BEGIN

    ALTER TABLE EDIShipmentOrder ADD 

    	OrderValue                DECIMAL(9,2)        NULL

    PRINT 'New column EDIShipmentOrder (08/28/2011)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentOrder' and COLUMN_NAME='SalesOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  ALTER TABLE EDIShipmentOrder DROP CONSTRAINT EDIShipmentOrderKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentOrder' and COLUMN_NAME='SalesOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  DROP INDEX EDIShipmentOrder.EDIShipmentOrderIdxOrder

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentOrder' and COLUMN_NAME='SalesOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

    ALTER TABLE EDIShipmentOrder ALTER COLUMN SalesOrder     CHAR(20) NOT NULL

    ALTER TABLE EDIShipmentOrder ALTER COLUMN Dispatch       CHAR(20)

    ALTER TABLE EDIShipmentOrder ALTER COLUMN Customer       CHAR(15)

    ALTER TABLE EDIShipmentOrder ALTER COLUMN MasterCustomer CHAR(15)

    ALTER TABLE EDIShipmentOrder ALTER COLUMN Weight         DECIMAL(12,0)

    ALTER TABLE EDIShipmentOrder ADD ActualWeight            DECIMAL(18,6)

    ALTER TABLE EDIShipmentOrder ALTER COLUMN Invoice        CHAR(20)

    ALTER TABLE EDIShipmentOrder ALTER COLUMN InvoiceDate    DATETIME

    ALTER TABLE EDIShipmentOrder ALTER COLUMN DeliveryNote   CHAR(20)

    ALTER TABLE EDIShipmentOrder ALTER COLUMN FreightCost    DECIMAL(14,2)

    ALTER TABLE EDIShipmentOrder ALTER COLUMN FreightCharge  DECIMAL(14,2)

    ALTER TABLE EDIShipmentOrder ALTER COLUMN ShipValue      DECIMAL(14,2)

    ALTER TABLE EDIShipmentOrder ALTER COLUMN OrderValue     DECIMAL(14,2)

    ALTER TABLE EDIShipmentOrder

     ADD CONSTRAINT EDIShipmentOrderKey PRIMARY KEY CLUSTERED

      (

         Shipment,

         SalesOrder

      )

    CREATE UNIQUE INDEX EDIShipmentOrderIdxOrder ON EDIShipmentOrder(

      SalesOrder,

      Dispatch,

      Shipment

     )

    PRINT 'Change columns EDIShipmentOrder (06/10/2013)'

END

GO



EXEC dbo.CadacusNewColumn '12/31/2013','C','EDIShipmentOrder','SCTReference',20,0

EXEC dbo.CadacusNewColumn '12/31/2013','C','EDIShipmentOrder','SourceWarehouse',10,0

EXEC dbo.CadacusNewColumn '12/31/2013','C','EDIShipmentOrder','TargetWarehouse',10,0

EXEC dbo.CadacusNewColumn '06/18/2017','C','EDIShipmentOrder','LineMultiShipCode',5,0

EXEC dbo.CadacusNewColumn '02/25/2019','N','EDIShipmentOrder','FreightActual',9,2

EXEC dbo.CadacusNewColumn '12/08/2020','N','EDIShipmentOrder','Tares',9,0

EXEC dbo.CadacusNewColumn '11/03/2021','N','EDIShipmentOrder','Document',9,0



PRINT 'Checking table EDIShipmentOrdPak'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentOrdPak' AND COLUMN_NAME='OrderNumber') = 1

BEGIN

  ALTER TABLE EDIShipmentOrdPak DROP CONSTRAINT EDIShipmentOrdPakKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentOrdPak' AND COLUMN_NAME='OrderNumber') = 1

BEGIN

  EXEC sp_rename 'EDIShipmentOrdPak.OrderNumber',        'SalesOrder',       'COLUMN';

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentOrdPak' and COLUMN_NAME='SalesOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  ALTER TABLE EDIShipmentOrdPak ALTER COLUMN SalesOrder  CHAR(20) NOT NULL

    

  ALTER TABLE EDIShipmentOrdPak

    ADD CONSTRAINT EDIShipmentOrdPakKey PRIMARY KEY CLUSTERED

     (

         ShipmentNumber,

         SalesOrder,

         PackNumber

     )

  PRINT 'Change columns EDIShipmentOrdPak (06/10/2013)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

	    WHERE TABLE_NAME='EDIShipmentOrdPak' AND COLUMN_NAME='Shipment') = 0

BEGIN

  EXEC dbo.CadacusDropPrimaryKey 'EDIShipmentOrdPak','X',1

  EXEC dbo.CadacusRenameColumn   '11/03/2021','EDIShipmentOrdPak','ShipmentNumber','Shipment','Y'

  EXEC dbo.CadacusRenameColumn   '11/03/2021','EDIShipmentOrdPak','PackNumber','Pack','Y'

  EXEC dbo.CadacusRenameColumn   '11/03/2021','EDIShipmentOrdPak','ActualPackNumber','ActualPack','Y'

  EXEC dbo.CadacusAddPrimaryKey  'EDIShipmentOrdPak','Shipment, SalesOrder, Pack'

END

GO



PRINT 'Checking table EDIShipmentPack'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentPack' AND COLUMN_NAME='Lenght') = 1

BEGIN

    EXEC sp_rename 'EDIShipmentPack.Lenght',      'Length',      'COLUMN';

    PRINT 'Rename column EDIShipmentPack  (06/19/2012)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentPack' AND COLUMN_NAME='Length' AND NUMERIC_SCALE=0) = 1

BEGIN

    ALTER TABLE EDIShipmentPack ALTER COLUMN Length DECIMAL(6,2);

    ALTER TABLE EDIShipmentPack ALTER COLUMN Width  DECIMAL(6,2);

    ALTER TABLE EDIShipmentPack ALTER COLUMN Height DECIMAL(6,2);

    PRINT 'Change columns EDIShipmentPack (02/16/2013)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentPack' AND COLUMN_NAME='User1') = 0

BEGIN

    ALTER TABLE EDIShipmentPack ADD User1 char(30)  NULL

    PRINT 'Add User1 column to EDIShipmentPack (04/06/2007)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentPack' AND COLUMN_NAME='TarePackLevel') = 0

BEGIN

    ALTER TABLE EDIShipmentPack ADD TarePackLevel           CHAR(1)            NULL

    PRINT 'New column EDIShipmentPack  (08/27/2010)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentPack' AND COLUMN_NAME='TrackingStatus') = 0

BEGIN

    ALTER TABLE EDIShipmentPack ADD 

     TrackingStatus           CHAR(1)             NULL

    PRINT 'New column EDIShipmentPack  (04/04/2011)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentPack' AND COLUMN_NAME='DecimalWeight') = 0

BEGIN

    ALTER TABLE EDIShipmentPack ADD 

     DecimalWeight            DECIMAL(6,2)        NULL

    PRINT 'New column EDIShipmentPack  (04/29/2011)'

END

GO



EXEC dbo.CadacusNewColumn '06/21/2011','N','EDIShipmentPack','FreightActual',9,2



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentPack' AND COLUMN_NAME='TrackingNumber2') = 0

BEGIN

    ALTER TABLE EDIShipmentPack ADD 

     TrackingNumber2          CHAR(30)            NULL

    PRINT 'New column EDIShipmentPack  (04/29/2013)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentPack' and COLUMN_NAME='PackWeight' and NUMERIC_PRECISION=4) = 1

BEGIN

  ALTER TABLE EDIShipmentPack ALTER COLUMN MerchandiseValue DECIMAL(14,2)

  ALTER TABLE EDIShipmentPack ALTER COLUMN MiscValue        DECIMAL(14,2)

  ALTER TABLE EDIShipmentPack ALTER COLUMN PackWeight       DECIMAL(12,0)

  ALTER TABLE EDIShipmentPack ALTER COLUMN DecimalWeight    DECIMAL(14,2)

  ALTER TABLE EDIShipmentPack ALTER COLUMN FreightActual    DECIMAL(14,2)

  ALTER TABLE EDIShipmentPack ALTER COLUMN FreightCost      DECIMAL(14,2)

  ALTER TABLE EDIShipmentPack ALTER COLUMN FreightCharge    DECIMAL(14,2)

  

    PRINT 'Change columns EDIShipmentPack (06/10/2013)'

END

GO



IF (dbo.CadacusIndexTest('EDIShipmentPackIdxMark') = 0)

BEGIN

  CREATE UNIQUE INDEX EDIShipmentPackIdxMark ON EDIShipmentPack(

    PackMark,

    ShipmentNumber,

    PackNumber

   )

   PRINT 'Add Index EDIShipmentPack (12/31/2013)'

END

GO



EXEC dbo.CadacusNewColumn '08/06/2014','C','EDIShipmentPack','PackCode',15,0

EXEC dbo.CadacusNewColumn '09/02/2015','C','EDIShipmentPack','CartonCode',30,0

EXEC dbo.CadacusNewColumn '08/02/2016','C','EDIShipmentPack','DGFlag',1,0

EXEC dbo.CadacusNewColumn '02/23/2018','C','EDIShipmentPack','Reference1',50,0

EXEC dbo.CadacusNewColumn '02/23/2018','C','EDIShipmentPack','Reference2',50,0

EXEC dbo.CadacusNewColumn '06/27/2018','C','EDIShipmentPack','Reference1Code',10,0

EXEC dbo.CadacusNewColumn '06/27/2018','C','EDIShipmentPack','Reference2Code',10,0



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

	    WHERE TABLE_NAME='EDIShipmentPack' AND COLUMN_NAME='Shipment') = 0

BEGIN

  EXEC dbo.CadacusDropPrimaryKey 'EDIShipmentPack','X',1

  EXEC dbo.CadacusDropIndex      'EDIShipmentPack','Tracking','X',1

  EXEC dbo.CadacusDropIndex      'EDIShipmentPack','Mark','X',1

  EXEC dbo.CadacusRenameColumn   '11/03/2021','EDIShipmentPack','ShipmentNumber','Shipment','Y'

  EXEC dbo.CadacusRenameColumn   '11/03/2021','EDIShipmentPack','PackNumber','Pack','Y'

  EXEC dbo.CadacusRenameColumn   '11/03/2021','EDIShipmentPack','TareNumber','Tare','Y'

  EXEC dbo.CadacusRenameColumn   '11/03/2021','EDIShipmentPack','TarePackLevel','LevelCode','Y'

  EXEC dbo.CadacusAddPrimaryKey  'EDIShipmentPack','Shipment, Pack'

  EXEC dbo.CadacusAddIndex       'EDIShipmentPack', 'Tracking', 'TrackingNumber,Shipment,Pack'

  EXEC dbo.CadacusAddIndex       'EDIShipmentPack', 'Mark', 'PackMark,Shipment,Pack'

END

GO



PRINT 'Checking table EDIShipmentSerials'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIShipmentSerials') = 0

BEGIN

    CREATE TABLE EDIShipmentSerials(

     Shipment                 DECIMAL(9,0)        NOT NULL,

     ItemNumber               DECIMAL(9,0)        NOT NULL,

     Serial                   CHAR(20)            NOT NULL,

     Status                   CHAR(1)             NULL,

     Quantity                 DECIMAL(10,3)       NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIShipmentSerialsKey PRIMARY KEY CLUSTERED

         (

          Shipment,

          ItemNumber,

          Serial

         )

    )

    PRINT 'New table EDIShipmentSerials (5/13/2010)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentSerials' and COLUMN_NAME='Serial' and CHARACTER_MAXIMUM_LENGTH=20) = 1

BEGIN

  ALTER TABLE EDIShipmentSerials DROP CONSTRAINT EDIShipmentSerialsKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentSerials' and COLUMN_NAME='Serial' and CHARACTER_MAXIMUM_LENGTH=20) = 1

BEGIN

    ALTER TABLE EDIShipmentSerials ALTER COLUMN Serial    CHAR(50)      NOT NULL

    ALTER TABLE EDIShipmentSerials ALTER COLUMN Quantity  DECIMAL(18,6)

 ALTER TABLE EDIShipmentSerials

  ADD CONSTRAINT EDIShipmentSerialsKey PRIMARY KEY CLUSTERED

  (

         Shipment,

         ItemNumber,

         Serial

  )

    PRINT 'Change columns EDIShipmentSerials (06/10/2013)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

	    WHERE TABLE_NAME='EDIShipmentSerials' AND COLUMN_NAME='Item') = 0

BEGIN

  EXEC dbo.CadacusDropPrimaryKey 'EDIShipmentSerials','X',1

  EXEC dbo.CadacusRenameColumn   '11/03/2021','EDIShipmentSerials','ItemNumber','Item','Y'

  EXEC dbo.CadacusAddPrimaryKey  'EDIShipmentSerials','Shipment,Item,Serial'

END

GO



PRINT 'Checking table EDIShipmentSplit'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIShipmentSplit') = 0

BEGIN

    CREATE TABLE EDIShipmentSplit(

     ShipmentNumber           DECIMAL(9,0)        NOT NULL,

     Split                    DECIMAL(4,0)        NOT NULL,

     Status                   CHAR(1)             NULL,

     Handheld                 CHAR(20)            NULL,

     Employee                 CHAR(6)             NULL,

     StatusDate               DATETIME            NULL,

     StatusTime               DECIMAL(8,0)        NULL,

     ExportDate               DATETIME            NULL,

     ExportTime               DECIMAL(8,0)        NULL,

     ImportDate               DATETIME            NULL,

     ImportTime               DECIMAL(8,0)        NULL,

     SaveDate                 DATETIME            NULL,

     SaveTime                 DECIMAL(8,0)        NULL,

     SaveElapsed              DECIMAL(9,0)        NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIShipmentSplitKey PRIMARY KEY CLUSTERED

         (

          ShipmentNumber,

          Split

         )

    )

    PRINT 'New table EDIShipmentSplit (01/18/2012)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentSplit' and COLUMN_NAME='Employee' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

    ALTER TABLE EDIShipmentSplit ALTER COLUMN Employee  CHAR(20)



    PRINT 'Change columns EDIShipmentSplit (06/10/2013)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentSplit' AND COLUMN_NAME='Archive') = 0

BEGIN

    ALTER TABLE EDIShipmentSplit ADD 

     Archive                  CHAR(200)           NULL

    PRINT 'New columns EDIShipmentSplit (05/14/2014)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

	    WHERE TABLE_NAME='EDIShipmentSplit' AND COLUMN_NAME='Shipment') = 0

BEGIN

  EXEC dbo.CadacusDropPrimaryKey 'EDIShipmentSplit','X',1

  EXEC dbo.CadacusRenameColumn   '11/03/2021','EDIShipmentSplit','ShipmentNumber','Shipment','Y'

  EXEC dbo.CadacusAddPrimaryKey  'EDIShipmentSplit','Shipment,Split'

END

GO



PRINT 'Checking table EDIShipmentSplitPk'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIShipmentSplitPk') = 0

BEGIN

    CREATE TABLE EDIShipmentSplitPk(

     ShipmentNumber           DECIMAL(9,0)        NOT NULL,

     UpdateDate               DATETIME            NOT NULL,

     UpdateTime               DECIMAL(8,0)        NOT NULL,

     Split                    DECIMAL(4,0)        NOT NULL,

     Line                     DECIMAL(4,0)        NOT NULL,

     Quantity                 DECIMAL(15,3)       NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIShipmentSplitPkKey PRIMARY KEY CLUSTERED

         (

          ShipmentNumber,

          UpdateDate,

          UpdateTime,

          Split,

          Line

         )

    )

    PRINT 'New table EDIShipmentSplitPk (01/18/2012)'

END



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentSplitPk' AND COLUMN_NAME='Bin') = 0

BEGIN

    ALTER TABLE EDIShipmentSplitPk ADD 

     Bin                  CHAR(20)           NULL

    PRINT 'New column EDIShipmentSplitPk (06/24/2014)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentSplitPk' AND COLUMN_NAME='TransferBin') = 0

BEGIN

    ALTER TABLE EDIShipmentSplitPk ADD 

     TransferBin                  CHAR(20)           NULL

    PRINT 'New column EDIShipmentSplitPk (11/03/2014)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentSplitPk' AND COLUMN_NAME='Lot') = 0

BEGIN

    ALTER TABLE EDIShipmentSplitPk ADD 

     Lot                  CHAR(50)           NULL

    PRINT 'New column EDIShipmentSplitPk (04/18/2016)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

	    WHERE TABLE_NAME='EDIShipmentSplitPk' AND COLUMN_NAME='Shipment') = 0

BEGIN

  EXEC dbo.CadacusDropPrimaryKey 'EDIShipmentSplitPk','X',1

  EXEC dbo.CadacusRenameColumn   '11/03/2021','EDIShipmentSplitPk','ShipmentNumber','Shipment','Y'

  EXEC dbo.CadacusAddPrimaryKey  'EDIShipmentSplitPk','Shipment,UpdateDate,UpdateTime,Split,Line'

END

GO



PRINT 'Checking table EDIShipmentSplitSe'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIShipmentSplitSe') = 0

BEGIN

    CREATE TABLE EDIShipmentSplitSe(

     ShipmentNumber           DECIMAL(9,0)        NOT NULL,

     Split                    DECIMAL(4,0)        NOT NULL,

     Line                     DECIMAL(4,0)        NOT NULL,

     Serial                   CHAR(50)            NOT NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIShipmentSplitSeKey PRIMARY KEY CLUSTERED

         (

          ShipmentNumber,

          Split,

          Line,

          Serial

         )

    )

    CREATE UNIQUE INDEX EDIShipmentSplitSeIdxSerial ON EDIShipmentSplitSe(

     Serial,

     ShipmentNumber,

     Split,

     Line

     )

    PRINT 'New table EDIShipmentSplitSe'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

	    WHERE TABLE_NAME='EDIShipmentSplitSe' AND COLUMN_NAME='Shipment') = 0

BEGIN

  EXEC dbo.CadacusDropPrimaryKey 'EDIShipmentSplitSe','X',1

  EXEC dbo.CadacusRenameColumn   '11/03/2021','EDIShipmentSplitSe','ShipmentNumber','Shipment','Y'

  EXEC dbo.CadacusAddPrimaryKey  'EDIShipmentSplitSe','Shipment,Split,Line,Serial'

END

GO



PRINT 'Checking table EDIShipmentTare'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentTare' AND COLUMN_NAME='TarePackLevel') = 0

BEGIN

    ALTER TABLE EDIShipmentTare ADD 

     TarePackLevel           CHAR(1)            NULL

    PRINT 'Add new column to EDIShipmentTare  (08/27/2010)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentTare' AND COLUMN_NAME='NMFCItem') = 0

BEGIN

    ALTER TABLE EDIShipmentTare ADD 

     NMFCItem                 CHAR(20)            NULL,

     NMFCClass                CHAR(10)            NULL

    PRINT 'Add new column to EDIShipmentTare  (12/19/2010)'

END

GO



IF (dbo.CadacusIndexTest('EDIShipmentTareIdxMark') = 0)

BEGIN

  CREATE UNIQUE INDEX EDIShipmentTareIdxMark ON EDIShipmentTare(

   TareMark,

   ShipmentNumber,

   TareNumber

   )

   PRINT 'Add Index EDIShipmentTare (12/31/2013)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentTare' and COLUMN_NAME='LicensePlate' and CHARACTER_MAXIMUM_LENGTH=30) = 1

BEGIN

  DROP INDEX EDIShipmentTare.EDIShipmentTareIdxPlate

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentTare' and COLUMN_NAME='LicensePlate' and CHARACTER_MAXIMUM_LENGTH=30) = 1

BEGIN

    ALTER TABLE EDIShipmentTare ALTER COLUMN LicensePlate CHAR(50) NULL

    PRINT 'Expand column to EDIShipmentTare  (02/18/2014)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentTare' AND COLUMN_NAME='TrackingNumber') = 0

BEGIN

    ALTER TABLE EDIShipmentTare ADD 

     TrackingNumber           CHAR(30)            NULL

    PRINT 'Add new column to EDIShipmentTare  (02/18/2014)'

END

GO



IF (dbo.CadacusIndexTest('EDIShipmentTareIdxTracking') = 0)

BEGIN

    CREATE UNIQUE INDEX EDIShipmentTareIdxTracking ON EDIShipmentTare(

     TrackingNumber,

     ShipmentNumber,

     TareNumber

     )

   PRINT 'Add Tracking Index EDIShipmentTare (02/18/2014)'

END

GO



IF (dbo.CadacusIndexTest('EDIShipmentTareIdxPlate') = 0)

BEGIN

    CREATE UNIQUE INDEX EDIShipmentTareIdxPlate ON EDIShipmentTare(

     LicensePlate,

     ShipmentNumber,

     TareNumber

     )

   PRINT 'Add LP Index EDIShipmentTare (02/18/2014)'

END

GO



EXEC dbo.CadacusNewColumn '02/27/2017','C','EDIShipmentTare','DimensionsCode',30,0

EXEC dbo.CadacusNewColumn '02/27/2017','N','EDIShipmentTare','Length',6,2

EXEC dbo.CadacusNewColumn '02/27/2017','N','EDIShipmentTare','Width',6,2

EXEC dbo.CadacusNewColumn '02/27/2017','N','EDIShipmentTare','Height',6,2

EXEC dbo.CadacusNewColumn '02/27/2017','C','EDIShipmentTare','DimensionsUOM',2,0



--!  The following 4 sections are to correct for putting the PalletWeight as a Char in the original issue.



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='EDIShipmentTare' and COLUMN_NAME='PalletWeight' and DATA_TYPE ='char') = 1

BEGIN

  EXEC dbo.CadacusNewColumnNoDefault '03/03/2017','N','EDIShipmentTare','PalletWeight2',6,2

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='EDIShipmentTare' and COLUMN_NAME='PalletWeight' and DATA_TYPE ='char') = 1

BEGIN

  DECLARE @UPD NCHAR(200)

  SET @UPD=N'UPDATE EDIShipmentTare Set PalletWeight2=cast(PalletWeight as Decimal(6,2)) where PalletWeight > '' '''

  EXEC sp_executesql @UPD

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='EDIShipmentTare' and COLUMN_NAME='PalletWeight' and DATA_TYPE ='char') = 1

BEGIN

  ALTER TABLE EDIShipmentTare DROP COLUMN PalletWeight

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='EDIShipmentTare' and COLUMN_NAME='PalletWeight2') = 1

BEGIN

  EXEC sp_rename 'EDIShipmentTare.PalletWeight2',   'PalletWeight',    'COLUMN';

END

GO



EXEC dbo.CadacusNewColumn '03/03/2017','N','EDIShipmentTare','PalletWeight',6,2



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

	    WHERE TABLE_NAME='EDIShipmentTare' AND COLUMN_NAME='Shipment') = 0

BEGIN

  EXEC dbo.CadacusDropPrimaryKey 'EDIShipmentTare','X',1

  EXEC dbo.CadacusDropIndex      'EDIShipmentTare','Mark','X',1

  EXEC dbo.CadacusDropIndex      'EDIShipmentTare','Tracking','X',1

  EXEC dbo.CadacusDropIndex      'EDIShipmentTare','Plate','X',1

  EXEC dbo.CadacusRenameColumn   '11/03/2021','EDIShipmentTare','ShipmentNumber','Shipment','Y'

  EXEC dbo.CadacusRenameColumn   '11/03/2021','EDIShipmentTare','TareNumber','Tare','Y'

  EXEC dbo.CadacusRenameColumn   '11/03/2021','EDIShipmentTare','TarePackLevel','LevelCode','Y'

  EXEC dbo.CadacusAddPrimaryKey  'EDIShipmentTare','Shipment,Tare'

  EXEC dbo.CadacusAddIndex       'EDIShipmentTare', 'Mark', 'TareMark,Shipment,Tare'

  EXEC dbo.CadacusAddIndex       'EDIShipmentTare', 'Tracking', 'TrackingNumber,Shipment,Tare'

  EXEC dbo.CadacusAddIndex       'EDIShipmentTare', 'Plate', 'LicensePlate,Shipment,Tare'

END

GO



PRINT 'Checking table EDIShipmentUPSBook'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUPSBook' AND COLUMN_NAME='IntlPackages') = 0

BEGIN

    ALTER TABLE EDIShipmentUPSBook ADD 

     IntlPackages             DECIMAL(6,0)        NULL,

     IntlShipments            DECIMAL(6,0)        NULL

    PRINT 'New columns EDIShipmentUPSBook (12/31/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUPSBook' and COLUMN_NAME='PickupDate' and CHARACTER_MAXIMUM_LENGTH=8) = 1

BEGIN

  ALTER TABLE EDIShipmentUPSBook DROP CONSTRAINT EDIShipmentUPSBookKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUPSBook' and COLUMN_NAME='PickupDate' and CHARACTER_MAXIMUM_LENGTH=8) = 1

BEGIN

  DROP INDEX EDIShipmentUPSBook.EDIShipmentUPSBookIdxDate

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUPSBook' and COLUMN_NAME='PickupDate' and CHARACTER_MAXIMUM_LENGTH=8) = 1

BEGIN

    ALTER TABLE EDIShipmentUPSBook ALTER COLUMN PickupDate DATETIME NOT NULL

 ALTER TABLE EDIShipmentUPSBook

  ADD CONSTRAINT EDIShipmentUPSBookKey PRIMARY KEY CLUSTERED

  (

         Account,

         Book,

         Page,

         PickupDate

  )

CREATE UNIQUE INDEX EDIShipmentUPSBookIdxDate ON EDIShipmentUPSBook(

 Account,

 PickupDate,

 Book,

 Page

 )

    

    PRINT 'Change columns EDIShipmentUPSBook (06/10/2013)'

END

GO





PRINT 'Checking table EDIShipmentUPSDtl'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUPSDtl' AND COLUMN_NAME='ProActive') = 0

BEGIN

    ALTER TABLE EDIShipmentUPSDtl ADD

     ProActive                CHAR(1)             NULL,

     InsuranceValue           DECIMAL(8,2)        NULL,

     ExchangeCollect          CHAR(1)             NULL,

     iscSeeds                 CHAR(1)             NULL,

     iscPerishable            CHAR(1)             NULL,

     iscTobacco               CHAR(1)             NULL,

     iscPlants                CHAR(1)             NULL,

     iscAlcohol               CHAR(1)             NULL,

     iscDiagSpec              CHAR(1)             NULL,

     iscSpecExcept            CHAR(1)             NULL,

     DryIce                   CHAR(1)             NULL,

     PaperlessInvoice         CHAR(1)             NULL,

     WorldEase                CHAR(1)             NULL,

     ThirdCtry                CHAR(1)             NULL

    PRINT 'New columns EDIShipmentUPSDtl (03/11/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUPSDtl' AND COLUMN_NAME='CarrierPkg') = 0

BEGIN

    ALTER TABLE EDIShipmentUPSDtl ADD

     CarrierPkg               CHAR(1)             NULL,

     ReturnService            CHAR(1)             NULL,

     VerbalConfirm            CHAR(1)             NULL,

     DlvryAreaSurcharge       CHAR(1)             NULL

    PRINT 'New columns EDIShipmentUPSDtl (08/25/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUPSDtl' AND COLUMN_NAME='InsurancePayor') = 0

BEGIN

    ALTER TABLE EDIShipmentUPSDtl ADD

     InsurancePayor           CHAR(1)             NULL

    PRINT 'New column EDIShipmentUPSDtl...InsurancePayor (12/04/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUPSDtl' AND COLUMN_NAME='Country') = 0

BEGIN

    ALTER TABLE EDIShipmentUPSDtl ADD

     Country                  CHAR(2)             NULL

    PRINT 'New column EDIShipmentUPSDtl...Country (12/31/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUPSDtl' AND COLUMN_NAME='Ref1') = 0

BEGIN

    ALTER TABLE EDIShipmentUPSDtl ADD

     Ref1                     CHAR(35)            NULL,

     Ref2                     CHAR(35)            NULL

    PRINT 'New columns EDIShipmentUPSDtl (05/26/2010)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUPSDtl' AND COLUMN_NAME='ShipDate' AND DATA_TYPE='char') = 1

BEGIN

   DROP INDEX EDIShipmentUPSDtl.EDIShipmentUPSDtlIdxBook

   PRINT 'Drop Index to allow column change on EDIShipmentUPSDtl (02/07/2012)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUPSDtl' AND COLUMN_NAME='ShipDate' AND DATA_TYPE='char') = 1

BEGIN

  ALTER TABLE EDIShipmentUPSDtl ALTER COLUMN ShipDate DateTime NULL

  CREATE UNIQUE INDEX EDIShipmentUPSDtlIdxBook ON EDIShipmentUPSDtl(

    ShipDate,

    Book,

    Page,

    ShipmentNumber,

    PackNumber,

    TrackingNumber

    )

   PRINT 'Change column type EDIShipmentUPSDtl (02/07/2012)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUPSDtl' AND COLUMN_NAME='ShipperRelease') = 0

BEGIN

    ALTER TABLE EDIShipmentUPSDtl ADD

     ShipperRelease          CHAR(1)             NULL

    PRINT 'New column EDIShipmentUPSDtl...ShipperRelease (05/28/2012)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUPSDtl' AND COLUMN_NAME='Ref3') = 0

BEGIN

    ALTER TABLE EDIShipmentUPSDtl ADD

     Ref3                     CHAR(35)            NULL,

     Ref4                     CHAR(35)            NULL,

     Ref1Code                 CHAR(2)             NULL,

     Ref2Code                 CHAR(2)             NULL,

     Ref3Code                 CHAR(2)             NULL,

     Ref4Code                 CHAR(2)             NULL

    PRINT 'New columns to EDIShipmentUPSDtl (11/14/2012)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUPSDtl' AND COLUMN_NAME='Length' AND NUMERIC_SCALE=0) = 1

BEGIN

    ALTER TABLE EDIShipmentUPSDtl ALTER COLUMN Length DECIMAL(6,2)

    ALTER TABLE EDIShipmentUPSDtl ALTER COLUMN Width  DECIMAL(6,2)

    ALTER TABLE EDIShipmentUPSDtl ALTER COLUMN Height DECIMAL(6,2)

    PRINT 'Change columns EDIShipmentUPSDtl (02/16/2013)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUPSDtl' and COLUMN_NAME='OrderNumber') = 1

BEGIN

  ALTER TABLE EDIShipmentUPSDtl DROP CONSTRAINT EDIShipmentUPSDtlKey

  DROP INDEX EDIShipmentUPSDtl.EDIShipmentUPSDtlIdxBook

  DROP INDEX EDIShipmentUPSDtl.EDIShipmentUPSDtlIdxCus

  DROP INDEX EDIShipmentUPSDtl.EDIShipmentUPSDtlIdxOrder

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUPSDtl' and COLUMN_NAME='OrderNumber') = 1

BEGIN

  EXEC sp_rename 'EDIShipmentUPSDtl.OrderNumber',        'SalesOrder',       'COLUMN';

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUPSDtl' and COLUMN_NAME='SalesOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

    ALTER TABLE EDIShipmentUPSDtl ALTER COLUMN SalesOrder       CHAR(20)

    ALTER TABLE EDIShipmentUPSDtl ALTER COLUMN Customer         CHAR(15)

    ALTER TABLE EDIShipmentUPSDtl ALTER COLUMN MerchandiseValue DECIMAL(14,2)

    ALTER TABLE EDIShipmentUPSDtl ALTER COLUMN MiscValue        DECIMAL(14,2)

    ALTER TABLE EDIShipmentUPSDtl ALTER COLUMN FreightCost      DECIMAL(14,2)

    ALTER TABLE EDIShipmentUPSDtl ALTER COLUMN FreightCharge    DECIMAL(14,2)

    ALTER TABLE EDIShipmentUPSDtl ALTER COLUMN MinValue         DECIMAL(14,2)

    ALTER TABLE EDIShipmentUPSDtl ALTER COLUMN OrderValue       DECIMAL(14,2)

    ALTER TABLE EDIShipmentUPSDtl ALTER COLUMN ShipValue        DECIMAL(14,2)

    ALTER TABLE EDIShipmentUPSDtl ALTER COLUMN CODTotal         DECIMAL(14,2)

ALTER TABLE EDIShipmentUPSDtl

  ADD CONSTRAINT EDIShipmentUPSDtlKey PRIMARY KEY CLUSTERED

  (

         TrackingNumber

  )



CREATE UNIQUE INDEX EDIShipmentUPSDtlIdxBook ON EDIShipmentUPSDtl(

 ShipDate,

 Book,

 Page,

 ShipmentNumber,

 PackNumber,

 TrackingNumber

 )



CREATE UNIQUE INDEX EDIShipmentUPSDtlIdxCus ON EDIShipmentUPSDtl(

 Customer,

 SalesOrder,

 TrackingNumber

 )



CREATE UNIQUE INDEX EDIShipmentUPSDtlIdxOrder ON EDIShipmentUPSDtl(

 SalesOrder,

 TrackingNumber

 )

    PRINT 'Change columns EDIShipmentUPSDtl (06/10/2013)'

END

GO



IF (SELECT CHARACTER_MAXIMUM_LENGTH FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUPSDtl' and COLUMN_NAME='EMail' ) <> 255

BEGIN

    ALTER TABLE EDIShipmentUPSDtl ALTER COLUMN EMail CHAR(255)

    PRINT 'Change columns EDIShipmentUPSDtl (06/27/2016)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUPSDtl' AND COLUMN_NAME='Hazardous') = 1

BEGIN

  EXEC sp_rename 'EDIShipmentUPSDtl.Hazardous',         'DGFlag',        'COLUMN';

  PRINT 'Rename column EDIShipmentUPSDtl (08/02/2016)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUPSDtl' AND COLUMN_NAME='DGFlag') = 0

BEGIN

    ALTER TABLE EDIShipmentUPSDtl ADD

     DGFlag           CHAR(1)             NULL

    PRINT 'New column EDIShipmentUPSDtl..DGFlag (08/02/2016)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUPSDtl' AND COLUMN_NAME='TareNumber') = 0

BEGIN

    ALTER TABLE EDIShipmentUPSDtl ADD

     TareNumber        DECIMAL(9,0)             NULL

    PRINT 'New column EDIShipmentUPSDtl..TareNumber (08/02/2016)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

	    WHERE TABLE_NAME='EDIShipmentUPSDtl' AND COLUMN_NAME='Shipment') = 0

BEGIN

  EXEC dbo.CadacusDropIndex    'EDIShipmentUPSDtl','Book','X',1

  EXEC dbo.CadacusRenameColumn '11/03/2021','EDIShipmentUPSDtl','ShipmentNumber','Shipment','Y'

  EXEC dbo.CadacusRenameColumn '11/03/2021','EDIShipmentUPSDtl','PackNumber','Pack','Y'

  EXEC dbo.CadacusRenameColumn '11/03/2021','EDIShipmentUPSDtl','TareNumber','Tare','Y'

  EXEC dbo.CadacusAddIndex     'EDIShipmentUPSDtl', 'Book', 'ShipDate,Book,Page,Shipment,TrackingNumber'

END

GO



PRINT 'Checking table EDIShipmentUSPS'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIShipmentUSPS') = 0

BEGIN

    CREATE TABLE EDIShipmentUSPS(

     EntryDate                DATETIME            NOT NULL,

     EntryTime                DECIMAL(8,0)        NOT NULL,

     Account                  CHAR(10)            NULL,

     Type                     CHAR(1)             NULL,

     Shipment                 DECIMAL(9,0)        NULL,

     SalesOrder               CHAR(6)             NULL,

     Pack                     DECIMAL(9,0)        NULL,

     Tracking                 CHAR(30)            NULL,

     Postage                  DECIMAL(11,2)       NULL,

     Balance                  DECIMAL(11,2)       NULL,

     Server                   CHAR(1)             NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIShipmentUSPSKey PRIMARY KEY CLUSTERED

         (

          EntryDate,

          EntryTime

         )

    )

    PRINT 'New table EDIShipmentUSPS'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentUSPS' and COLUMN_NAME='SalesOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

    ALTER TABLE EDIShipmentUSPS ALTER COLUMN SalesOrder  CHAR(20)

    PRINT 'Change columns EDIShipmentUSPS (06/10/2013)'

END

GO



PRINT 'Checking table EDIShipmentVfyDTL'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIShipmentVfyDTL') = 0

BEGIN

    CREATE TABLE EDIShipmentVfyDTL(

     Tracking                 CHAR(30)            NOT NULL,

     StockCode                CHAR(30)            NOT NULL,

     Quantity                 DECIMAL(18,6)       NULL,

     VerifiedQuantity         DECIMAL(18,6)       NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIShipmentVfyDTLKey PRIMARY KEY CLUSTERED

         (

          Tracking,

          StockCode

         )

    )

    PRINT 'New table EDIShipmentVfyDTL (05/26/2014)'

END

GO



PRINT 'Checking table EDIShipmentVfy'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIShipmentVfy') = 0

BEGIN

    CREATE TABLE EDIShipmentVfy(

     Tracking                 CHAR(30)            NOT NULL,

     ShipmentNumber           DECIMAL(9,0)        NULL,

     Status                   CHAR(1)             NULL,

     SalesOrder               CHAR(20)            NULL,

     Split                    DECIMAL(4,0)        NULL,

     SaveHandheld             CHAR(20)            NULL,

     SaveEmployee             CHAR(20)            NULL,

     SaveDate                 DATETIME            NULL,

     SaveTime                 DECIMAL(8,0)        NULL,

     VerifyHandheld           CHAR(20)            NULL,

     VerifyEmployee           CHAR(20)            NULL,

     VerifyDate               DATETIME            NULL,

     VerifyTime               DECIMAL(8,0)        NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIShipmentVfyKey PRIMARY KEY CLUSTERED

         (

          Tracking

         )

    )

    CREATE UNIQUE INDEX EDIShipmentVfyIdxShipment ON EDIShipmentVfy(

     ShipmentNumber,

     Tracking

     )

    PRINT 'New table EDIShipmentVfy (05/26/2014)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIShipmentVfy' AND COLUMN_NAME='Split') = 0

BEGIN

    ALTER TABLE EDIShipmentVfy ADD

     Split                    DECIMAL(4,0)        NULL,

     SaveHandheld             CHAR(20)            NULL,

     SaveEmployee             CHAR(20)            NULL,

     SaveDate                 DATETIME            NULL,

     SaveTime                 DECIMAL(8,0)        NULL,

     VerifyHandheld           CHAR(20)            NULL,

     VerifyEmployee           CHAR(20)            NULL,

     VerifyDate               DATETIME            NULL,

     VerifyTime               DECIMAL(8,0)        NULL

    PRINT 'New columns EDIShipmentVfy (06/13/2014)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

	    WHERE TABLE_NAME='EDIShipmentVfy' AND COLUMN_NAME='Shipment') = 0

BEGIN

  EXEC dbo.CadacusDropIndex    'EDIShipmentVfy','Shipment','X',1

  EXEC dbo.CadacusRenameColumn '11/03/2021','EDIShipmentVfy','ShipmentNumber','Shipment','Y'

  EXEC dbo.CadacusAddIndex     'EDIShipmentVfy', 'Shipment', 'Shipment,Tracking'

END

GO



PRINT 'Checking table EDITakeItem'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDITakeItem' and COLUMN_NAME='Serial' and CHARACTER_MAXIMUM_LENGTH=20) = 1

BEGIN

  ALTER TABLE EDITakeItem ALTER COLUMN Quantity    DECIMAL(18,6)

  ALTER TABLE EDITakeItem ALTER COLUMN Serial      CHAR(50)

  ALTER TABLE EDITakeItem ALTER COLUMN Lot         CHAR(50)

  ALTER TABLE EDITakeItem ALTER COLUMN Bin         CHAR(20)



  PRINT 'Change columns EDITakeItem (06/10/2013)'

END

GO



PRINT 'Checking table EDITakeMaster'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDITakeMaster' AND COLUMN_NAME='Unit') = 0

BEGIN

    ALTER TABLE EDITakeMaster ADD Unit char(20) NULL

    PRINT 'New column EDITakeMaster..Unit (02/29/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDITakeMaster' and COLUMN_NAME='Employee' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  ALTER TABLE EDITakeMaster ALTER COLUMN Employee    CHAR(20)

  ALTER TABLE EDITakeMaster ALTER COLUMN Warehouse   CHAR(10)



  PRINT 'Change columns EDITakeMaster (06/10/2013)'

END

GO





PRINT 'Checking table EDITracking'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDITracking' and COLUMN_NAME='Number' and CHARACTER_MAXIMUM_LENGTH=15) = 1

BEGIN

  ALTER TABLE EDITracking DROP CONSTRAINT EDITrackingKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDITracking' and COLUMN_NAME='Number' and CHARACTER_MAXIMUM_LENGTH=15) = 1

BEGIN

  EXEC sp_rename 'EDITracking.Number',         'Code',        'COLUMN';

  EXEC sp_rename 'EDITracking.OperatorCode',   'Operator',    'COLUMN';

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDITracking' and COLUMN_NAME='Code' and CHARACTER_MAXIMUM_LENGTH=15) = 1

BEGIN

  ALTER TABLE EDITracking ALTER COLUMN Code  CHAR(20) NOT NULL

  ALTER TABLE EDITracking ALTER COLUMN Operator CHAR(20)

  



 ALTER TABLE EDITracking

  ADD CONSTRAINT EDITrackingKey PRIMARY KEY CLUSTERED

  (

         Code,

         Status

  )



  PRINT 'Change columns EDITracking (06/10/2013)'

END

GO



PRINT 'Checking table EDIUPSAlcohol'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIUPSAlcohol') = 0

BEGIN

    CREATE TABLE EDIUPSAlcohol(

     Country                  CHAR(2)             NOT NULL,

     State                    CHAR(2)             NOT NULL,

     Allowed                  CHAR(1)             NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIUPSAlcoholKey PRIMARY KEY CLUSTERED

         (

          Country,

          State

         )

    )

    PRINT 'New table EDIUPSAlcohol'

END

GO



PRINT 'Checking table EDIUPSCommit'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIUPSCommit') = 0

BEGIN

    CREATE TABLE EDIUPSCommit(

     Postal                   CHAR(10)            NOT NULL,

     Iata                     CHAR(2)             NOT NULL,

     City                     CHAR(20)            NOT NULL,

     InOutLimit               CHAR(3)             NOT NULL,

     EarlyAM                  CHAR(4)             NULL,

     OneDay                   CHAR(4)             NULL,

     TwoDay                   CHAR(4)             NULL,

     SatEarlyAM               CHAR(4)             NULL,

     Sat1Day                  CHAR(4)             NULL,

     Sat2Day                  CHAR(4)             NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIUPSCommitKey PRIMARY KEY CLUSTERED

         (

          Postal,

          Iata,

          City,

          InOutLimit

         )

    )

    PRINT 'New table EDIUPSCommit'

END

GO



PRINT 'Checking table EDIUPSInvoice'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIUPSInvoice') = 0

BEGIN

    CREATE TABLE EDIUPSInvoice(

     Iata                     CHAR(2)             NOT NULL,

     Name                     CHAR(40)            NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIUPSInvoiceKey PRIMARY KEY CLUSTERED

         (

          Iata

         )

    )

    PRINT 'New table EDIUPSInvoice'

END

GO



PRINT 'Checking table EDIUPSOptions'

GO

IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIUPSOptions') = 0

BEGIN

    CREATE TABLE EDIUPSOptions(

     Account                  CHAR(6)             NOT NULL,

     Item                     CHAR(30)            NOT NULL,

     Info                     CHAR(50)            NULL,

     InfoValue                DECIMAL(17,6)       NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIUPSOptionsKey PRIMARY KEY CLUSTERED

         (

          Account,

          Item

         )

    )

    PRINT 'New table EDIUPSOptions (03/11/2008)'

END

GO



PRINT 'Checking table EDIUPSServiceLevel'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIUPSServiceLevel') = 0

BEGIN

    CREATE TABLE EDIUPSServiceLevel(

     Service                  CHAR(2)             NOT NULL,

     Confirmation             CHAR(1)             NOT NULL,

     Saturday                 CHAR(1)             NOT NULL,

     Cod                      CHAR(1)             NOT NULL,

     ShipperRelease           CHAR(1)             NOT NULL,

     ExchangeCollect          CHAR(1)             NOT NULL,

     Attempts                 CHAR(1)             NOT NULL,

     ServiceType              CHAR(2)             NULL,

     ServiceLevel             CHAR(2)             NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIUPSServiceLevelKey PRIMARY KEY CLUSTERED

         (

          Service,

          Confirmation,

          Saturday,

          Cod,

          ShipperRelease,

          ExchangeCollect,

          Attempts

         )

    )

    PRINT 'New table EDIUPSServiceLevel'

END

GO



PRINT 'Checking table EDIUPSPricing'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIUPSPricing') = 0

BEGIN

    CREATE TABLE EDIUPSPricing(

     Service                  CHAR(2)             NOT NULL,

     ServiceFlag              CHAR(1)             NOT NULL,

     HundredWght              CHAR(1)             NOT NULL,

     ZoneNumber               CHAR(3)             NOT NULL,

     Tier                     CHAR(2)             NOT NULL,

     Packaged                 CHAR(5)             NOT NULL,

     Weight                   DECIMAL(4,0)        NOT NULL,

     Cost                     DECIMAL(6,2)        NULL,

     CostFlag                 CHAR(1)             NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIUPSPricingKey PRIMARY KEY CLUSTERED

         (

          Service,

          ServiceFlag,

          HundredWght,

          ZoneNumber,

          Tier,

          Packaged,

          Weight

         )

    )

    PRINT 'New table EDIUPSPricing'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIUPSPricing' and COLUMN_NAME='RateCode') = 0

BEGIN

  ALTER TABLE EDIUPSPricing DROP CONSTRAINT EDIUPSPricingKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIUPSPricing' and COLUMN_NAME='RateCode') = 0

BEGIN

    ALTER TABLE EDIUPSPricing ADD RateCode CHAR(1) NOT NULL CONSTRAINT Syspro_DF_EDIUPSPricing_RateCode DEFAULT ' '



    ALTER TABLE EDIUPSPricing ADD

     CONSTRAINT EDIUPSPricingKey PRIMARY KEY CLUSTERED

         (

          RateCode,

          Service,

          ServiceFlag,

          HundredWght,

          ZoneNumber,

          Tier,

          Packaged,

          Weight

         )



    PRINT 'Update table EDIUPSPricing (06/29/2016)'

END

GO



IF (SELECT COUNT(*) FROM EDIUPSPricing

	WHERE RateCode=' ') > 0

BEGIN

  UPDATE EDIUPSPricing SET RateCode='D' WHERE RateCode=' '

END

GO



PRINT 'Checking table EDIUPSRoutes'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIUPSRoutes') = 0

BEGIN

    CREATE TABLE EDIUPSRoutes(

     Country                  CHAR(2)             NOT NULL,

     StartingPostalCode       CHAR(10)            NOT NULL,

     EndingPostalCode         CHAR(10)            NULL,

     RouteCode                CHAR(20)            NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIUPSRoutesKey PRIMARY KEY CLUSTERED

         (

          Country,

          StartingPostalCode

         )

    )

    PRINT 'New table EDIUPSRoutes'

END

GO



PRINT 'Checking table EDIUPSSurcharges'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIUPSSurcharges') = 0

BEGIN

    CREATE TABLE EDIUPSSurcharges(

     Country                  CHAR(2)             NOT NULL,

     PostalStart              CHAR(10)            NOT NULL,

     City                     CHAR(30)            NOT NULL,

     PostalEnd                CHAR(10)            NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIUPSSurchargesKey PRIMARY KEY CLUSTERED

         (

          Country,

          PostalStart,

          City

         )

    )

    PRINT 'New table EDIUPSSurcharges'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIUPSSurcharges' AND COLUMN_NAME='Extended') = 0

BEGIN

    ALTER TABLE EDIUPSSurcharges ADD

     Extended                 CHAR(1)             NULL

    PRINT 'New column EDIUPSSurcharges...Extended (01/06/2009)'

END

GO



PRINT 'Checking table EDIUPSZones'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIUPSZones') = 0

BEGIN

    CREATE TABLE EDIUPSZones(

     Country                  CHAR(2)             NOT NULL,

     FromStartingCode         CHAR(5)             NOT NULL,

     ToStartingCode           CHAR(10)            NOT NULL,

     FromEndingCode           CHAR(5)             NULL,

     ToEndingCode             CHAR(10)            NULL,

     ZoneInfo                 CHAR(100)           NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIUPSZonesKey PRIMARY KEY CLUSTERED

         (

          Country,

          FromStartingCode,

          ToStartingCode

         )

    )

    PRINT 'New table EDIUPSZones'

END

GO



PRINT 'Checking table EDIXRefAccounts'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefAccounts' AND COLUMN_NAME='ShipperName') = 0

BEGIN

    ALTER TABLE EDIXRefAccounts ADD ShipperName char(50) NULL

    ALTER TABLE EDIXRefAccounts ADD ShipperAddress char(50) NULL

    ALTER TABLE EDIXRefAccounts ADD ShipperCity    char(30) NULL

    ALTER TABLE EDIXRefAccounts ADD ShipperState   char(2) NULL

    ALTER TABLE EDIXRefAccounts ADD ShipperZip     char(10) NULL

    ALTER TABLE EDIXRefAccounts ADD Contact        char(50) NULL

    ALTER TABLE EDIXRefAccounts ADD Commissioned   char(1) NULL

    PRINT 'Add Address Fields in EDIXRefAccounts (09/06/2007)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefAccounts' AND COLUMN_NAME='cwtEnabled') = 0

BEGIN

    ALTER TABLE EDIXRefAccounts ADD cwtEnabled        char(1) NULL

    ALTER TABLE EDIXRefAccounts ADD domesDimWtDiv     decimal(3,0) NULL

    ALTER TABLE EDIXRefAccounts ADD dropShipIndicator char(1) NULL

    ALTER TABLE EDIXRefAccounts ADD gndSvcIndicator   char(2) NULL

    ALTER TABLE EDIXRefAccounts ADD intlDimWtDivisor  decimal(3,0) NULL

    ALTER TABLE EDIXRefAccounts ADD canadaDimWtDiv    decimal(3,0) NULL

    ALTER TABLE EDIXRefAccounts ADD groundDimWtDiv    decimal(3,0) NULL

    ALTER TABLE EDIXRefAccounts ADD schdSatPkUp       char(1) NULL

    ALTER TABLE EDIXRefAccounts ADD ncCwtEnabled      char(1) NULL

    ALTER TABLE EDIXRefAccounts ADD internatShipPOA   char(1) NULL

    ALTER TABLE EDIXRefAccounts ADD iscSeeds          char(3) NULL

    ALTER TABLE EDIXRefAccounts ADD iscPerishables    char(3) NULL

    ALTER TABLE EDIXRefAccounts ADD iscTobacco        char(3) NULL

    ALTER TABLE EDIXRefAccounts ADD iscPlants         char(3) NULL

    ALTER TABLE EDIXRefAccounts ADD iscAlcohol        char(3) NULL

    ALTER TABLE EDIXRefAccounts ADD iscDiagSpec       char(3) NULL

    ALTER TABLE EDIXRefAccounts ADD iscSpecExcept     char(3) NULL

    ALTER TABLE EDIXRefAccounts ADD proActiveResponse char(3) NULL

    PRINT 'Add UPS Fields in EDIXRefAccounts (10/18/2007)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefAccounts' AND COLUMN_NAME='DGPhone') = 0

BEGIN

    ALTER TABLE EDIXRefAccounts ADD DGPhone          char(15) NULL

    ALTER TABLE EDIXRefAccounts ADD DGForm           char(1) NULL

    ALTER TABLE EDIXRefAccounts ADD DGPrinter        char(50) NULL

    PRINT 'Add Fields in EDIXRefAccounts (04/21/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefAccounts' AND COLUMN_NAME='NewPostage') = 0

BEGIN

    ALTER TABLE EDIXRefAccounts ADD 

     NewPostage               DECIMAL(11,2)       NULL,

     AutoBuy                  CHAR(1)             NULL,

     MinPostage               DECIMAL(11,2)       NULL

    PRINT 'Add Fields in EDIXRefAccounts (12/02/2011)'

END

GO



/*IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefAccounts' AND COLUMN_NAME='WebKey') = 0

BEGIN

    ALTER TABLE EDIXRefAccounts ADD 

     WebKey                   CHAR(30)            NULL,

     WebAccount               CHAR(30)            NULL,

     WebMeter                 CHAR(30)            NULL,

     WebPassword              CHAR(30)            NULL,

     WebServer                CHAR(1)             NULL

    PRINT 'Add Fields in EDIXRefAccounts (01/10/2013)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefAccounts' AND COLUMN_NAME='WebUS') = 0

BEGIN

    ALTER TABLE EDIXRefAccounts ADD 

     WebUS                    CHAR(1)             NULL,

     WebNonUS                 CHAR(1)             NULL

    PRINT 'Add Fields in EDIXRefAccounts (12/15/2015)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefAccounts' AND COLUMN_NAME='DGSigName') = 0

BEGIN

    ALTER TABLE EDIXRefAccounts ADD 

     DGSigName                CHAR(35)            NULL,

     DGSigTitle               CHAR(35)            NULL,

     DGSigPlace               CHAR(35)            NULL

    PRINT 'Add Fields in EDIXRefAccounts (12/18/2015)'

END

GO  */



EXEC dbo.CadacusNewColumn   '01/10/2013','C','EDIXRefAccounts','WebKey',30,0

EXEC dbo.CadacusNewColumn   '01/10/2013','C','EDIXRefAccounts','WebAccount',30,0

EXEC dbo.CadacusNewColumn   '01/10/2013','C','EDIXRefAccounts','WebMeter',30,0

EXEC dbo.CadacusNewColumn   '01/10/2013','C','EDIXRefAccounts','WebPassword',30,0

EXEC dbo.CadacusNewColumn   '01/10/2013','C','EDIXRefAccounts','WebServer',1,0



EXEC dbo.CadacusNewColumn   '12/15/2015','C','EDIXRefAccounts','WebUS',1,0

EXEC dbo.CadacusNewColumn   '12/15/2015','C','EDIXRefAccounts','WebNonUS',1,0



EXEC dbo.CadacusNewColumn   '12/18/2015','C','EDIXRefAccounts','DGSigName',35,0

EXEC dbo.CadacusNewColumn   '12/18/2015','C','EDIXRefAccounts','DGSigTitle',35,0

EXEC dbo.CadacusNewColumn   '12/18/2015','C','EDIXRefAccounts','DGSigPlace',35,0





EXEC dbo.CadacusNewColumn   '02/16/2018','C','EDIXRefAccounts','LabelDirectory',200,0

EXEC dbo.CadacusNewColumn   '02/16/2018','C','EDIXRefAccounts','Reference1',50,0

EXEC dbo.CadacusNewColumn   '02/16/2018','C','EDIXRefAccounts','Reference2',50,0

EXEC dbo.CadacusNewColumn   '02/16/2018','C','EDIXRefAccounts','DebugLog',1,0

EXEC dbo.CadacusNewColumn   '04/18/2018','C','EDIXRefAccounts','LabelCode',30,0

EXEC dbo.CadacusNewColumn   '03/21/2021','C','EDIXRefAccounts','CustomsComment',150,0

EXEC dbo.CadacusAlterColumn '02/07/2022','C','EDIXRefAccounts','Description',50,0

EXEC dbo.CadacusAlterColumn '02/07/2022','C','EDIXRefAccounts','Number',100,0

EXEC dbo.CadacusAlterColumn '02/07/2022','C','EDIXRefAccounts','Contents',50,0

EXEC dbo.CadacusAlterColumn '02/07/2022','C','EDIXRefAccounts','WebKey',100,0

EXEC dbo.CadacusAlterColumn '02/07/2022','C','EDIXRefAccounts','WebAccount',100,0

EXEC dbo.CadacusAlterColumn '02/07/2022','C','EDIXRefAccounts','WebMeter',100,0

EXEC dbo.CadacusAlterColumn '02/07/2022','C','EDIXRefAccounts','WebPassword',100,0



EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','TrackingFlag'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','DCurrentFirst'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','DCurrentLast'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','DCurrentFixed'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','DNextFirst'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','DNextLast'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','DNextFixed'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','CommonTracking'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','CommonAccount'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','iscSeeds'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','iscPerishables'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','iscTobacco'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','iscPlants'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','iscAlcohol'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','iscDiagSpec'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','iscSpecExcept'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','proActiveResponse'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','domesDimWtDiv'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','dropShipIndicator'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','gndSvcIndicator'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','intlDimWtDivisor'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','canadaDimWtDiv'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','groundDimWtDiv'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','schdSatPkUp'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','ncCwtEnabled'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','internatShipPOA'



EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','WebTestKey'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','WebTestAccount'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','WebTestMeter'

EXEC dbo.CadacusDropColumn  '02/07/2022','EDIXRefAccounts','WebTestPassword'



PRINT 'Checking table EDIXRefAddress'

GO



EXEC dbo.CadacusNewColumn '08/26/2008','C','EDIXRefAddress','EDIFACTFlag',1,0

EXEC dbo.CadacusNewColumn '10/01/2008','C','EDIXRefAddress','Cta0201',3,0

EXEC dbo.CadacusNewColumn '11/12/2008','C','EDIXRefAddress','SCTFlag',1,0

EXEC dbo.CadacusNewColumn '12/18/2008','C','EDIXRefAddress','RemoveModifier',1,0

EXEC dbo.CadacusNewColumn '02/24/2010','C','EDIXRefAddress','CmntIncLoc',1,0

EXEC dbo.CadacusNewColumn '02/24/2010','C','EDIXRefAddress','CmntIncName',1,0

EXEC dbo.CadacusNewColumn '07/19/2010','C','EDIXRefAddress','AddrLookup',3,0

EXEC dbo.CadacusNewColumn '07/19/2010','C','EDIXRefAddress','IDLookup',3,0

EXEC dbo.CadacusNewColumn '01/30/2012','C','EDIXRefAddress','Per07',2,0

EXEC dbo.CadacusNewColumn '01/30/2012','C','EDIXRefAddress','Per08',50,0

EXEC dbo.CadacusNewColumn '01/30/2012','C','EDIXRefAddress','PER08CustomFldType',6,0

EXEC dbo.CadacusNewColumn '01/30/2012','C','EDIXRefAddress','PER08CustomFldName',6,0

EXEC dbo.CadacusNewColumn '03/29/2016','C','EDIXRefAddress','IgnoreLineL',1,0

EXEC dbo.CadacusNewColumn '06/17/2020','C','EDIXRefAddress','AddrCffLookup',4,0

EXEC dbo.CadacusNewColumn '06/17/2020','C','EDIXRefAddress','Per06Location',1,0

EXEC dbo.CadacusNewColumn '04/13/2021','C','EDIXRefAddress','CheckOrder',1,0

EXEC dbo.CadacusNewColumn '06/15/2022','C','EDIXRefAddress','ReverseL1L2',1,0



--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIXRefAddress' AND COLUMN_NAME='EDIFACTFlag') = 0

--BEGIN

--    ALTER TABLE EDIXRefAddress ADD

--     EDIFACTFlag              CHAR(1)             NULL

--    PRINT 'New column EDIXRefAddress (08/26/2008)'

--END

--GO



--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIXRefAddress' AND COLUMN_NAME='Cta0201') = 0

--BEGIN

--    ALTER TABLE EDIXRefAddress ADD

--     Cta0201              CHAR(3)             NULL

--    PRINT 'New column EDIXRefAddress...Cta0201 (10/01/2008)'

--END

--GO



--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIXRefAddress' AND COLUMN_NAME='SCTFlag') = 0

--BEGIN

--    ALTER TABLE EDIXRefAddress ADD

--     SCTFlag              CHAR(1)             NULL

--    PRINT 'New column EDIXRefAddress...SCTFlag (11/12/2008)'

--END

--GO



--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIXRefAddress' AND COLUMN_NAME='RemoveModifier') = 0

--BEGIN

--    ALTER TABLE EDIXRefAddress ADD

--     RemoveModifier             CHAR(1)             NULL

--    PRINT 'New column EDIXRefAddress...RemoveModifier (12/18/2008)'

--END

--GO



--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIXRefAddress' AND COLUMN_NAME='CmntIncLoc') = 0

--BEGIN

--    ALTER TABLE EDIXRefAddress ADD

--     CmntIncLoc               CHAR(1)             NULL,

--     CmntIncName              CHAR(1)             NULL

--    PRINT 'New columns EDIXRefAddress (02/24/2010)'

--END

--GO



--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIXRefAddress' AND COLUMN_NAME='AddrLookup') = 0

--BEGIN

--    ALTER TABLE EDIXRefAddress ADD

--     AddrLookup               CHAR(3)             NULL,

--     IDLookup                 CHAR(3)             NULL

--    PRINT 'New columns EDIXRefAddress (07/19/2010)'

--END

--GO



--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIXRefAddress' AND COLUMN_NAME='Per07') = 0

--BEGIN

--    ALTER TABLE EDIXRefAddress ADD

--     Per07                    CHAR(2)             NULL,

--     Per08                    CHAR(50)            NULL,

--     PER08CustomFldType       CHAR(6)             NULL,

--     PER08CustomFldName       CHAR(6)             NULL

--    PRINT 'New columns EDIXRefAddress (01/30/2012)'

--END

--GO



--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIXRefAddress' AND COLUMN_NAME='IgnoreLineL') = 0

--BEGIN

--    ALTER TABLE EDIXRefAddress ADD

--     IgnoreLineL              CHAR(1)             NULL

--    PRINT 'New columns EDIXRefAddress (03/29/2016)'

--END

--GO



PRINT 'Checking table EDIXRefAllowance'

GO



EXEC dbo.CadacusNewColumn '04/11/2008','C','EDIXRefAllowance','AgencyOption',1,0

EXEC dbo.CadacusNewColumn '04/11/2008','C','EDIXRefAllowance','Tracking',1,0

EXEC dbo.CadacusNewColumn '02/04/2011','C','EDIXRefAllowance','ACCodeCredit',4,0

EXEC dbo.CadacusNewColumn '08/07/2011','C','EDIXRefAllowance','ReverseIndicator',1,0



--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIXRefAllowance' AND COLUMN_NAME='AgencyOption') = 0

--BEGIN

--    ALTER TABLE EDIXRefAllowance ADD

--     AgencyOption            CHAR(1)             NULL,

--     Tracking                CHAR(1)             NULL

--    PRINT 'New columns EDIXRefAllowance (04/11/2008)'

--END

--GO



--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIXRefAllowance' AND COLUMN_NAME='ACCodeCredit') = 0

--BEGIN

--    ALTER TABLE EDIXRefAllowance ADD

--     ACCodeCredit             CHAR(4)             NULL

--    PRINT 'New column EDIXRefAllowance (02/04/2011)'

--END

--GO



--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIXRefAllowance' AND COLUMN_NAME='ReverseIndicator') = 0

--BEGIN

--    ALTER TABLE EDIXRefAllowance ADD

--     ReverseIndicator         CHAR(1)             NULL

--    PRINT 'New column EDIXRefAllowance (08/07/2011)'

--END

--GO



PRINT 'Checking table EDIXRefBin'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIXRefBin') = 0

BEGIN

    CREATE TABLE EDIXRefBin(

     Bin                      CHAR(6)             NOT NULL,

     Warehouse                CHAR(2)             NOT NULL,

     Location                 CHAR(30)            NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIXRefBinKey PRIMARY KEY CLUSTERED

         (

          Bin,

          Warehouse

         )

    )

    PRINT 'New table EDIXRefBin'

END

GO



EXEC dbo.CadacusDropPrimaryKey 'EDIXRefBin','Bin',20



EXEC dbo.CadacusAlterColumn '06/10/2013','C','EDIXRefBin','Bin',20,0

EXEC dbo.CadacusAlterColumn '06/10/2013','C','EDIXRefBin','Warehouse',10,0



EXEC dbo.CadacusAddPrimaryKey 'EDIXRefBin','Bin, Warehouse'



EXEC dbo.CadacusAlterColumn '06/10/2013','C','EDIXRefBin','Location',50,0



EXEC dbo.CadacusNewColumn '10/11/2016','C','EDIXRefBin','PickZone',20,0

EXEC dbo.CadacusNewColumn '10/11/2016','C','EDIXRefBin','Type',1,0

EXEC dbo.CadacusNewColumn '10/11/2016','N','EDIXRefBin','Priority',2,0



EXEC dbo.CadacusNewColumn '11/01/2016','C','EDIXRefBin','AOMAllocations',1,0

EXEC dbo.CadacusNewColumn '11/01/2016','C','EDIXRefBin','Web',1,0

GO





PRINT 'Checking table EDIXRefBinType'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIXRefBinType') = 0

BEGIN

    CREATE TABLE EDIXRefBinType(

     Warehouse                CHAR(10)            NOT NULL,

     BinType                  CHAR(20)            NOT NULL,

     Description              CHAR(50)            NULL,

     FlowType                 CHAR(10)            NULL,

     AllowMultiProduct        CHAR(1)             NULL,

     AllowMultiLot            CHAR(1)             NULL,

     AutoReplenish            CHAR(1)             NULL,

     DimensionUnit            CHAR(20)            NULL,

     PhysicalLength           DECIMAL(12,6)       NULL,

     PhysicalWidth            DECIMAL(12,6)       NULL,

     PhysicalHeight           DECIMAL(12,6)       NULL,

     MassUnit                 CHAR(20)            NULL,

     MassMax                  DECIMAL(18,6)       NULL,

     VolumeUnit               CHAR(20)            NULL,

     VolumeMax                DECIMAL(18,6)       NULL,

     StorageSecurity          CHAR(20)            NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIXRefBinTypeKey PRIMARY KEY CLUSTERED

         (

          Warehouse,

          BinType

         )

    )

    PRINT 'New table EDIXRefBinType'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'WmsBinType') = 1

BEGIN

 IF (SELECT COUNT(*) FROM WmsBinType) > 0

 BEGIN

  IF (SELECT COUNT(*) FROM EDIXRefBinType) = 0

  BEGIN

    Insert Into [EDIXRefBinType] 

     (

       [Warehouse]

      ,[BinType]

      ,[Description]

      ,[FlowType]

      ,[AllowMultiProduct]

      ,[AllowMultiLot]

      ,[AutoReplenish]

      ,[DimensionUnit]

      ,[PhysicalLength]

      ,[PhysicalWidth]

      ,[PhysicalHeight]

      ,[MassUnit]

      ,[MassMax]

      ,[VolumeUnit]

      ,[VolumeMax]

      ,[StorageSecurity]

     )

     SELECT  [Warehouse]

      ,[BinType]

      ,[Description]

      ,[FlowType]

      ,[AllowMultiProduct]

      ,[AllowMultiLot]

      ,[AutoReplenish]

      ,[DimensionUnit]

      ,[PhysicalLength]

      ,[PhysicalWidth]

      ,[PhysicalHeight]

      ,[MassUnit]

      ,[MassMax]

      ,[VolumeUnit]

      ,[VolumeMax]

      ,[StorageSecurity]

    FROM [WmsBinType]



    PRINT 'Moving data from WmsBinType to EDIXRefBinType'

  END

 END

END

GO



PRINT 'Checking table EDIXRefCarrierInfo'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefCarrierInfo' AND COLUMN_NAME='Code') = 0

BEGIN

    EXEC sp_rename 'EDIXRefCarrierInfo.Extra',   'Code',    'COLUMN';

    EXEC sp_rename 'EDIXRefCarrierInfo.Service', 'SubCode', 'COLUMN';

    ALTER TABLE EDIXRefCarrierInfo DROP CONSTRAINT EDIXRefCarrierInfoKey

    ALTER TABLE EDIXRefCarrierInfo ALTER COLUMN Code char(30) not null

    ALTER TABLE EDIXRefCarrierInfo ALTER COLUMN SubCode char(20) not null

    ALTER TABLE EDIXRefCarrierInfo

    ADD CONSTRAINT EDIXRefCarrierInfoKey PRIMARY KEY CLUSTERED

       (

         CarrierSCAC,

         Code,

         SubCode

       )

    PRINT 'Change Key Fields in EDIXRefCarrierInfo (09/06/2007)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefCarrierInfo' AND COLUMN_NAME='EffectiveDate') = 0

BEGIN

    ALTER TABLE EDIXRefCarrierInfo ADD

     EffectiveDate            DATETIME            NULL

    PRINT 'New column EDIXRefCarrierInfo...EffectiveDate (12/04/2008)'

END

GO



PRINT 'Checking table EDIXRefCarrierSCAC'

GO



EXEC dbo.CadacusNewColumn   '02/15/2012','N','EDIXRefCarrierSCAC','ProStart',12,0

EXEC dbo.CadacusNewColumn   '02/15/2012','N','EDIXRefCarrierSCAC','ProEnd',12,0

EXEC dbo.CadacusNewColumn   '02/15/2012','N','EDIXRefCarrierSCAC','ProLast',12,0

EXEC dbo.CadacusNewColumn   '02/15/2012','N','EDIXRefCarrierSCAC','ProMin',12,0

EXEC dbo.CadacusNewColumn   '02/15/2012','C','EDIXRefCarrierSCAC','ProCheck',1,0

EXEC dbo.CadacusNewColumn   '08/27/2012','C','EDIXRefCarrierSCAC','ProHead',10,0

EXEC dbo.CadacusNewColumn   '08/27/2012','C','EDIXRefCarrierSCAC','ProTail',10,0

EXEC dbo.CadacusNewColumn   '12/11/2013','C','EDIXRefCarrierSCAC','Address1',50,0

EXEC dbo.CadacusNewColumn   '12/11/2013','C','EDIXRefCarrierSCAC','Address2',50,0

EXEC dbo.CadacusNewColumn   '12/11/2013','C','EDIXRefCarrierSCAC','Address3',50,0

EXEC dbo.CadacusNewColumn   '12/11/2013','C','EDIXRefCarrierSCAC','Address4',50,0

EXEC dbo.CadacusNewColumn   '08/27/2015','C','EDIXRefCarrierSCAC','ProTailPos',1,0

EXEC dbo.CadacusNewColumn   '11/28/2016','C','EDIXRefCarrierSCAC','TrackingUrl',200,0

EXEC dbo.CadacusAlterColumn '02/21/2017','C','EDIXRefCarrierSCAC','Supplier',15,0

EXEC dbo.CadacusNewColumn   '03/27/2020','N','EDIXRefCarrierSCAC','ProCheckWeight',2,0

EXEC dbo.CadacusNewColumn   '03/27/2020','C','EDIXRefCarrierSCAC','ProCheckWeightFlag',1,0

GO



IF (SELECT COUNT(*) FROM EDIXRefCarrierSCAC WHERE ProTailPos IS NULL) > 0

BEGIN

  UPDATE EDIXRefCarrierSCAC SET ProTailPos='N' WHERE ProTailPos IS NULL

END

GO



PRINT 'Checking table EDIXRefCFFTrans'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIXRefCFFTrans') = 0

BEGIN

    CREATE TABLE EDIXRefCFFTrans(

     FormType                 CHAR(6)             NOT NULL,

     FieldName                CHAR(6)             NOT NULL,

     FieldValue               CHAR(80)            NOT NULL,

     UpperValue               CHAR(80)            NULL,

     Translated               CHAR(80)            NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIXRefCFFTransKey PRIMARY KEY CLUSTERED

         (

          FormType,

          FieldName,

          FieldValue

         )

    )

    CREATE UNIQUE INDEX EDIXRefCFFTransIdxUpper ON EDIXRefCFFTrans(

     FormType,

     FieldName,

     UpperValue

     )

    PRINT 'New table EDIXRefCFFTrans'

END

GO



PRINT 'Checking table EDIXRefChargeRef'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefChargeRef' and COLUMN_NAME='Customer' and CHARACTER_MAXIMUM_LENGTH=7) = 1

BEGIN

  ALTER TABLE EDIXRefChargeRef DROP CONSTRAINT EDIXRefChargeRefKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefChargeRef' and COLUMN_NAME='Customer' and CHARACTER_MAXIMUM_LENGTH=7) = 1

BEGIN

    ALTER TABLE EDIXRefChargeRef ALTER COLUMN Customer      CHAR(15) NOT NULL

    ALTER TABLE EDIXRefChargeRef ALTER COLUMN AddrCode      CHAR(20) NOT NULL

    ALTER TABLE EDIXRefChargeRef ALTER COLUMN FrtMinValue   DECIMAL(14,2)

    ALTER TABLE EDIXRefChargeRef ALTER COLUMN OrderMinValue DECIMAL(14,2)

    ALTER TABLE EDIXRefChargeRef ALTER COLUMN PAClass       CHAR(20) 

    ALTER TABLE EDIXRefChargeRef ALTER COLUMN PAValue       DECIMAL(15,5)

    ALTER TABLE EDIXRefChargeRef ALTER COLUMN DAClass       CHAR(20) 

    ALTER TABLE EDIXRefChargeRef ALTER COLUMN DAValue       DECIMAL(15,5)



ALTER TABLE EDIXRefChargeRef

  ADD CONSTRAINT EDIXRefChargeRefKey PRIMARY KEY CLUSTERED

  (

         CarrierSCAC,

         Code,

         Customer,

         AddrCode

  )

    PRINT 'Change columns EDIXRefChargeRef (06/10/2013)'

END

GO



EXEC dbo.CadacusNewColumn   '12/11/2016','N','EDIXRefChargeRef','PAWeight',5,0

EXEC dbo.CadacusAlterColumn '09/04/2018','C','EDIXRefChargeRef','Charge',20,0

EXEC dbo.CadacusAlterColumn '09/04/2018','C','EDIXRefChargeRef','AltCharge',20,0

GO



PRINT 'Checking table EDIXRefCharges'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefCharges' AND COLUMN_NAME='MinBasis') = 0

BEGIN

    ALTER TABLE EDIXRefCharges ADD 

     ChargeMethod       CHAR(1)             NULL,

     FixedCharge        DECIMAL(6,2)        NULL,

     Percentage         DECIMAL(4,2)        NULL,

     MinBasis           CHAR(1)             NULL

    PRINT 'Add columns to EDIXRefCharges (12/15/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefCharges' AND COLUMN_NAME='InsuranceMinimum') = 0

BEGIN

    ALTER TABLE EDIXRefCharges ADD 

     InsuranceMinimum   DECIMAL(6,2)        NULL,

     InsuranceValue     DECIMAL(6,2)        NULL

    PRINT 'Add columns to EDIXRefCharges (09/29/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefCharges' AND COLUMN_NAME='MinFixed') = 0

BEGIN

    ALTER TABLE EDIXRefCharges ADD 

     MinFixed                 DECIMAL(6,2)        NULL,

     ChargeRounding           CHAR(1)             NULL

    PRINT 'Add columns to EDIXRefCharges (03/14/2011)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefCharges' AND COLUMN_NAME='MinFlagGround') = 0

BEGIN

    ALTER TABLE EDIXRefCharges ADD 

     MinFlagGround            CHAR(1)             NULL

    PRINT 'Add columns to EDIXRefCharges (08/28/2011)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefCharges' AND COLUMN_NAME='ServiceFlag') = 0

BEGIN

    ALTER TABLE EDIXRefCharges ADD 

     ServiceFlag            CHAR(1)             NULL

    PRINT 'Add columns to EDIXRefCharges (12/09/2012)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefCharges' AND COLUMN_NAME='CostFlag') = 0

BEGIN

    ALTER TABLE EDIXRefCharges ADD 

     CostFlag            CHAR(1)             NULL

    PRINT 'Add columns to EDIXRefCharges (05/10/2013)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefCharges' AND COLUMN_NAME='ScriptFile') = 0

BEGIN

    ALTER TABLE EDIXRefCharges ADD 

     ScriptFile               CHAR(100)           NULL,

     ScriptFunction           CHAR(30)            NULL    

    PRINT 'Add columns to EDIXRefCharges (05/26/2014)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefCharges' AND COLUMN_NAME='ChargeRateCode') = 0

BEGIN

    ALTER TABLE EDIXRefCharges ADD 

     ChargeRateCode         CHAR(1)           NULL,

     CostRateCode           CHAR(1)            NULL    

    PRINT 'Add columns to EDIXRefCharges (06/29/2016)'

END

GO



EXEC dbo.CadacusNewColumn        '09/04/2018','C','EDIXRefCharges','MinValueCFF',6,0

EXEC dbo.CadacusDropPrimaryKey   'EDIXRefCharges','Code',20

EXEC dbo.CadacusAlterColumn      '09/04/2018','C','EDIXRefCharges','Code',20,0

EXEC dbo.CadacusAddPrimaryKey    'EDIXRefCharges','Type, Code'

EXEC dbo.CadacusAlterColumn      '09/04/2018','C','EDIXRefCharges','Description',50,0

EXEC dbo.CadacusNewColumn        '10/10/2018','C','EDIXRefCharges','Customs',1,0

EXEC dbo.CadacusNewColumn        '01/21/2019','C','EDIXRefCharges','Distribution',1,0

GO



PRINT 'Checking table EDIXRefCommissions'

GO



IF (SELECT CHARACTER_MAXIMUM_LENGTH  FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefCommissions' AND COLUMN_NAME='Commission') = 1

BEGIN

    ALTER TABLE EDIXRefCommissions

    		ALTER COLUMN Commission CHAR(2) NULL

    PRINT 'Expand Commission column in EDIXRefCommmissions (05/25/2012)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefCommissions' and COLUMN_NAME='Salesman' and CHARACTER_MAXIMUM_LENGTH=3) = 1

BEGIN

  ALTER TABLE EDIXRefCommissions DROP CONSTRAINT EDIXRefCommissionsKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefCommissions' and COLUMN_NAME='Salesman' and CHARACTER_MAXIMUM_LENGTH=3) = 1

BEGIN

    ALTER TABLE EDIXRefCommissions ALTER COLUMN Salesman      CHAR(20) NOT NULL

    ALTER TABLE EDIXRefCommissions ALTER COLUMN Class         CHAR(10) NOT NULL



 ALTER TABLE EDIXRefCommissions

   ADD CONSTRAINT EDIXRefCommissionsKey PRIMARY KEY CLUSTERED

   (

          Partner,

          Salesman,

          Class,

          StockCode

   )



    PRINT 'Change columns EDIXRefCommissions (06/10/2013)'

END

GO



PRINT 'Checking table EDIXRefComPaths'

GO



/*IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefComPaths' AND COLUMN_NAME='FTPPort') = 0

BEGIN

    ALTER TABLE EDIXRefComPaths ADD FTPPort decimal(5,0) NULL

    ALTER TABLE EDIXRefComPaths ADD ProxyType char(1) NULL

    ALTER TABLE EDIXRefComPaths ADD ProxyUsername char(30) NULL

    ALTER TABLE EDIXRefComPaths ADD ProxyPassword char(30) NULL

    ALTER TABLE EDIXRefComPaths ADD ProxyServer char(50) NULL

    ALTER TABLE EDIXRefComPaths ADD ProxyPort decimal(5,0) NULL

    ALTER TABLE EDIXRefComPaths ADD RunCommand char(1) NULL

    ALTER TABLE EDIXRefComPaths ADD BeforeSort char(200) NULL

    ALTER TABLE EDIXRefComPaths ADD AfterCombine char(200) NULL

    ALTER TABLE EDIXRefComPaths ADD BeforeFTP char(200) NULL

    ALTER TABLE EDIXRefComPaths ADD AfterFTP char(200) NULL

    PRINT 'Add new columns to EDIXRefComPaths  (03/06/2007)'

END

GO*/



/*IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefComPaths' AND COLUMN_NAME='FTPPutFlag') = 0

BEGIN

    ALTER TABLE EDIXRefComPaths ADD 

     FTPPutFlag               CHAR(1)             NULL,

     FTPPutCommand            CHAR(100)           NULL

    PRINT 'Add new columns to EDIXRefComPaths  (04/21/2008)'

END

GO*/





/*IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefComPaths' AND COLUMN_NAME='FileType') = 0

BEGIN

    ALTER TABLE EDIXRefComPaths ADD 

    FileType                 CHAR(1)             NULL

    PRINT 'Add new column to EDIXRefComPaths  (09/15/2009)'

END

GO*/



/*IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefComPaths' AND COLUMN_NAME='DelayBefore') = 0

BEGIN

    ALTER TABLE EDIXRefComPaths ADD 

     DelayBefore              DECIMAL(4,0)        NULL,

     DelayAfter               DECIMAL(4,0)        NULL

    PRINT 'Add new column to EDIXRefComPaths  (05/06/2010)'

END

GO*/



/*IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefComPaths' AND COLUMN_NAME='Protocol') = 0

BEGIN

    ALTER TABLE EDIXRefComPaths ADD 

     Protocol                 CHAR(1)             NULL,

     SecureType               CHAR(1)             NULL,

     Timeout                  DECIMAL(4,0)        NULL

    PRINT 'Add new column to EDIXRefComPaths  (05/22/2010)'

END

GO*/



/*IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefComPaths' AND COLUMN_NAME='FTPGetSingle') = 0

BEGIN

    ALTER TABLE EDIXRefComPaths ADD 

     FTPGetSingle             CHAR(1)             NULL

    PRINT 'Add new column to EDIXRefComPaths  (07/13/2010)'

END

GO*/



/*IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefComPaths' AND COLUMN_NAME='FTPGetCommand') = 0

BEGIN

    ALTER TABLE EDIXRefComPaths ADD 

     FTPGetCommand             CHAR(100)             NULL

    PRINT 'Add new column to EDIXRefComPaths  (03/26/2012)'

END

GO*/



/*IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefComPaths' AND COLUMN_NAME='FTPGetCommandStart') = 0

BEGIN

    ALTER TABLE EDIXRefComPaths ADD 

     FTPGetCommandStart       CHAR(100)           NULL

    PRINT 'Add new column to EDIXRefComPaths  (07/08/2014)'

END

GO*/



/*IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefComPaths' AND COLUMN_NAME='FTPPutCommandStart') = 0

BEGIN

    ALTER TABLE EDIXRefComPaths ADD 

     FTPPutCommandStart       CHAR(100)           NULL

    PRINT 'Add new column to EDIXRefComPaths  (07/14/2014)'

END

GO*/



/*IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefComPaths' AND COLUMN_NAME='FTPOldUsername') = 0

BEGIN

    EXEC sp_rename 'EDIXRefComPaths.FTPUsername',   'FTPOldUsername',    'COLUMN';

    ALTER TABLE EDIXRefComPaths ADD 

    FTPUsername               CHAR(40)             NULL

    PRINT 'Expand FTPUsername in EDIXRefComPaths (03/08/2012)'

END

GO*/



EXEC dbo.CadacusNewColumn        '03/06/2007','N','EDIXRefComPaths','FTPPort',5,0

EXEC dbo.CadacusNewColumn        '03/06/2007','C','EDIXRefComPaths','ProxyType',1,0

EXEC dbo.CadacusNewColumn        '03/06/2007','C','EDIXRefComPaths','ProxyUsername',30,0

EXEC dbo.CadacusNewColumn        '03/06/2007','C','EDIXRefComPaths','ProxyPassword',30,0

EXEC dbo.CadacusNewColumn        '03/06/2007','C','EDIXRefComPaths','ProxyServer',50,0

EXEC dbo.CadacusNewColumn        '03/06/2007','N','EDIXRefComPaths','ProxyPort',5,0

EXEC dbo.CadacusNewColumn        '03/06/2007','C','EDIXRefComPaths','RunCommand',1,0

EXEC dbo.CadacusNewColumn        '03/06/2007','C','EDIXRefComPaths','BeforeSort',200,0

EXEC dbo.CadacusNewColumn        '03/06/2007','C','EDIXRefComPaths','AfterCombine',200,0

EXEC dbo.CadacusNewColumn        '03/06/2007','C','EDIXRefComPaths','BeforeFTP',200,0

EXEC dbo.CadacusNewColumn        '03/06/2007','C','EDIXRefComPaths','AfterFTP',200,0

EXEC dbo.CadacusNewColumn        '04/21/2008','C','EDIXRefComPaths','FTPPutFlag',1,0

EXEC dbo.CadacusNewColumn        '04/21/2008','C','EDIXRefComPaths','FTPPutCommand',100,0

EXEC dbo.CadacusNewColumn        '09/15/2009','C','EDIXRefComPaths','FileType',1,0

EXEC dbo.CadacusNewColumn        '05/06/2010','N','EDIXRefComPaths','DelayBefore',4,0

EXEC dbo.CadacusNewColumn        '05/06/2010','N','EDIXRefComPaths','DelayAfter',4,0

EXEC dbo.CadacusNewColumn        '05/22/2010','C','EDIXRefComPaths','Protocol',1,0

EXEC dbo.CadacusNewColumn        '05/22/2010','C','EDIXRefComPaths','SecureType',1,0

EXEC dbo.CadacusNewColumn        '05/22/2010','N','EDIXRefComPaths','Timeout',4,0

EXEC dbo.CadacusNewColumn        '07/13/2010','C','EDIXRefComPaths','FTPGetSingle',1,0

EXEC dbo.CadacusNewColumn        '03/26/2012','C','EDIXRefComPaths','FTPGetCommand',100,0

EXEC dbo.CadacusNewColumn        '07/08/2014','C','EDIXRefComPaths','FTPGetCommandStart',100,0

EXEC dbo.CadacusNewColumn        '07/14/2014','C','EDIXRefComPaths','FTPPutCommandStart',100,0



EXEC dbo.CadacusAlterColumn      '01/20/2022','C','EDIXRefComPaths','Description',50,0

EXEC dbo.CadacusAlterColumn      '01/20/2022','C','EDIXRefComPaths','FTPUsername',50,0

EXEC dbo.CadacusAlterColumn      '01/20/2022','C','EDIXRefComPaths','FTPPassword',50,0

GO 



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefComPaths' AND COLUMN_NAME='FTPOldUsername') = 1

BEGIN

    EXEC ('UPDATE EDIXRefComPaths SET FTPUsername=FTPOldUsername WHERE FTPOldUsername > '' '' AND FTPUsername <= '' ''')

--    UPDATE EDIXRefComPaths SET FTPUsername=FTPOldUsername WHERE FTPOldUsername > ' ' AND FTPUsername <= ' '

    ALTER TABLE EDIXRefComPaths DROP COLUMN FTPOldUsername

    PRINT 'Remove FTPOldUsername in EDIXRefComPaths (01/20/2022)'

END

GO



PRINT 'Checking table EDIXRefContainer'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIXRefContainer') = 0

BEGIN

    CREATE TABLE EDIXRefContainer(

     ContainerType            CHAR(20)            NOT NULL,

     Description              CHAR(50)            NULL,

     IsCarrier                CHAR(1)             NULL,

     DimensionUnit            CHAR(20)            NULL,

     PhysicalLength           DECIMAL(12,6)       NULL,

     PhysicalWidth            DECIMAL(12,6)       NULL,

     PhysicalHeight           DECIMAL(12,6)       NULL,

     MassUnit                 CHAR(20)            NULL,

     MassMax                  DECIMAL(18,6)       NULL,

     VolumeUnit               CHAR(20)            NULL,

     VolumeMax                DECIMAL(18,6)       NULL,

     SerialTrack              CHAR(1)             NULL,

     SerialIssue              CHAR(1)             NULL,

     SerialPrefix             CHAR(15)            NULL,

     SerialSuffix             CHAR(15)            NULL,

     VolumeSelf               DECIMAL(18,6)       NULL,

     MassSelf                 DECIMAL(18,6)       NULL,

     UseOriginalFlag          CHAR(1)             NULL,

     UomCode                  CHAR(20)            NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIXRefContainerKey PRIMARY KEY CLUSTERED

         (

          ContainerType

         )

    )

    PRINT 'New table EDIXRefContainer'

END

GO



EXEC dbo.CadacusNewColumn '11/02/2019','C','EDIXRefContainer','Type',1,0

EXEC dbo.CadacusNewColumn '11/02/2019','C','EDIXRefContainer','LpnType',1,0

EXEC dbo.CadacusNewColumn '11/28/2019','C','EDIXRefContainer','Single',1,0

EXEC dbo.CadacusNewColumn '07/21/2021','C','EDIXRefContainer','WarehouseFlag',1,0



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'WmsBinContainerTyp') = 1

BEGIN

 IF (SELECT COUNT(*) FROM WmsBinContainerTyp) > 0

 BEGIN

  IF (SELECT COUNT(*) FROM EDIXRefContainer) = 0

  BEGIN

    Insert INTO [EDIXRefContainer]

     (

       [ContainerType]

      ,[Description]

      ,[IsCarrier]

      ,[DimensionUnit]

      ,[PhysicalLength]

      ,[PhysicalWidth]

      ,[PhysicalHeight]

      ,[MassUnit]

      ,[MassMax]

      ,[VolumeUnit]

      ,[VolumeMax]

      ,[SerialTrack]

      ,[SerialIssue]

      ,[SerialPrefix]

      ,[SerialSuffix]

      ,[VolumeSelf]

      ,[MassSelf]

      ,[UseOriginalFlag]

      ,[UomCode]

     )

     SELECT

       [BinContainType] as ContainerTyp

      ,[Description]

      ,[IsCarrier]

      ,[DimensionUnit]

      ,[PhysicalLength]

      ,[PhysicalWidth]

      ,[PhysicalHeight]

      ,[MassUnit]

      ,[MassMax]

      ,[VolumeUnit]

      ,[VolumeMax]

      ,[SerialTrack]

      ,[SerialIssue]

      ,[SerialPrefix]

      ,[SerialSuffix]

      ,[VolumeSelf]

      ,[MassSelf]

      ,[UseOriginalFlag]

      ,[UomCode]

        FROM WmsBinContainerTyp

  

    Insert INTO [EDINext]

     (

       [System]

      ,[Type]

      ,[NextValue]

      ,[LastDate]

     )

     SELECT 

       'EDILPM' as [System]

      ,[BinContainType] as ContainerTyp

      ,LastSerialNumber 

      ,GETDATE() as LastDate

        FROM WmsBinContainerTyp

 

    PRINT 'Data moved from WmsBinContainerTyp to EDIXRefContainer and EDINext'

  END

 END

END

GO



PRINT 'Checking table EDIXRefDangerous'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIXRefDangerous') = 0

BEGIN

    CREATE TABLE EDIXRefDangerous(

     Code                     CHAR(30)            NOT NULL,

     ProperName               CHAR(51)            NULL,

     TechnicalName            CHAR(50)            NULL,

     DOTClass                 CHAR(5)             NULL,

     PackingType              CHAR(35)            NULL,

     PackingGroup             CHAR(3)             NULL,

     PackingInstruc           CHAR(4)             NULL,

     LabelCode                CHAR(50)            NULL,

     HandlingInfo             CHAR(175)           NULL,

     Flag                     CHAR(1)             NULL,

     IDNumber                 CHAR(4)             NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIXRefDangerousKey PRIMARY KEY CLUSTERED

         (

          Code

         )

    )

    PRINT 'New table EDIXRefDangerous (04/21/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefDangerous' AND COLUMN_NAME='Sequence') = 0

BEGIN

    ALTER TABLE EDIXRefDangerous ADD 

     DGAuthorization          CHAR(148)           NULL,

     CargoOnly                CHAR(1)             NULL,

     Sequence                 CHAR(2)             NULL

    ALTER TABLE EDIXRefDangerous ALTER COLUMN ProperName CHAR(120)

    ALTER TABLE EDIXRefDangerous ALTER COLUMN TechnicalName CHAR(255)

    PRINT 'Add/Expand columns in EDIXRefDangerous (12/18/2014)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefDangerous' AND COLUMN_NAME='RegulationSet') = 0

BEGIN

    ALTER TABLE EDIXRefDangerous ADD 

     RegulationSet            CHAR(1)             NULL

    PRINT 'Add column in EDIXRefDangerous (07/17/2016)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefDangerous' AND COLUMN_NAME='EXNumber') = 0

BEGIN

    ALTER TABLE EDIXRefDangerous ADD 

     EXNumber            CHAR(50)             NULL

    PRINT 'Add column in EDIXRefDangerous (08/30/2016)'

END

GO



PRINT 'Checking table EDIXRefDateTime'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefDateTime' AND COLUMN_NAME='ShippingOld') = 0

BEGIN

    EXEC sp_rename 'EDIXRefDateTime.ShippingDays',   'ShippingOld',    'COLUMN';

    ALTER TABLE EDIXRefDateTime ADD ShippingDays     DECIMAL(4,0)        NULL

    PRINT 'Expand ShippingDays in EDIXRefDateTime (06/02/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefDateTime' AND COLUMN_NAME='ScriptFile') = 0

BEGIN

    ALTER TABLE EDIXRefDateTime ADD

     ScriptFile               CHAR(100)           NULL,

     ScriptFunction           CHAR(50)            NULL

    PRINT 'New Scripting columns EDIXRefDateTime (01/17/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefDateTime' AND COLUMN_NAME='TimeFlag') = 0

BEGIN

    ALTER TABLE EDIXRefDateTime ADD

     TimeFlag                 CHAR(1)             NULL,

     FixedTime                CHAR(8)             NULL,

     TimeCodeFlag             CHAR(1)             NULL,

     TimeCode                 CHAR(2)             NULL

    PRINT 'New Scripting columns EDIXRefDateTime (02/24/2011)'

END

GO



EXEC dbo.CadacusNewColumn        '11/22/2019','D','EDIXRefDateTime','FixedDate',0,0



PRINT 'Checking table EDIXRefDimensions'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefDimensions' AND COLUMN_NAME='CarrierPkg') = 0

BEGIN

    ALTER TABLE EDIXRefDimensions ADD

     CarrierPkg               CHAR(1)             NULL

    PRINT 'New column EDIXRefDimensions (08/25/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefDimensions' and COLUMN_NAME='DimensionalUOM' and CHARACTER_MAXIMUM_LENGTH=2) = 1

BEGIN

    ALTER TABLE EDIXRefDimensions ALTER COLUMN DimensionalUOM CHAR(10)

    ALTER TABLE EDIXRefDimensions ALTER COLUMN WeightUOM      CHAR(10)

    ALTER TABLE EDIXRefDimensions ALTER COLUMN Description    CHAR(50)

    ALTER TABLE EDIXRefDimensions ALTER COLUMN EachUOM        CHAR(10) 

    ALTER TABLE EDIXRefDimensions ALTER COLUMN InnerUOM       CHAR(10) 

    ALTER TABLE EDIXRefDimensions ALTER COLUMN CartonUOM      CHAR(10) 



    PRINT 'Change columns EDIXRefDimensions (06/10/2013)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefDimensions' AND COLUMN_NAME='StockCode') = 0

BEGIN

    ALTER TABLE EDIXRefDimensions ADD

     StockCode               CHAR(30)             NULL

    PRINT 'New column EDIXRefDimensions (09/02/2015)'

END

GO



--!  The following 4 sections are to correct for putting the PalletWeight as a Char in the original issue.



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='EDIXRefDimensions' and COLUMN_NAME='PalletWeight' and DATA_TYPE ='char') = 1

BEGIN

  EXEC dbo.CadacusNewColumnNoDefault '03/03/2017','N','EDIXRefDimensions','PalletWeight2',6,2

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='EDIXRefDimensions' and COLUMN_NAME='PalletWeight' and DATA_TYPE ='char') = 1

BEGIN

  DECLARE @UPD NCHAR(200)

  SET @UPD=N'UPDATE EDIXRefDimensions Set PalletWeight2=cast(PalletWeight as Decimal(6,2)) where PalletWeight > '' '''

  EXEC sp_executesql @UPD

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='EDIXRefDimensions' and COLUMN_NAME='PalletWeight' and DATA_TYPE ='char') = 1

BEGIN

  ALTER TABLE EDIXRefDimensions DROP COLUMN PalletWeight

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='EDIXRefDimensions' and COLUMN_NAME='PalletWeight2') = 1

BEGIN

  EXEC sp_rename 'EDIXRefDimensions.PalletWeight2',   'PalletWeight',    'COLUMN';

END

GO



EXEC dbo.CadacusNewColumn '03/03/2017','N','EDIXRefDimensions','PalletWeight',6,2

EXEC dbo.CadacusNewColumn '03/23/2021','C','EDIXRefDimensions','Cubing',1,0

EXEC dbo.CadacusNewColumn '03/03/2017','N','EDIXRefDimensions','MaxWeight',6,2

EXEC dbo.CadacusNewColumn '11/09/2021','C','EDIXRefDimensions','Pack',1,0

EXEC dbo.CadacusNewColumn '11/09/2021','C','EDIXRefDimensions','Tare',1,0



EXEC dbo.CadacusDropPrimaryKey   'EDIXRefDimensions','Customer',15

EXEC dbo.CadacusNewColumnNotNull '01/14/2021','C','EDIXRefDimensions','Customer',15,0

EXEC dbo.CadacusAddPrimaryKey    'EDIXRefDimensions','Code, Partner, Customer'

EXEC dbo.CadacusAddIndex         'EDIXRefDimensions', 'Customer', 'Code, Customer, Partner'



EXEC dbo.CadacusNewColumn '11/09/2021','C','EDIXRefDimensions','PackCode',1,0

EXEC dbo.CadacusNewColumn '11/09/2021','C','EDIXRefDimensions','TareCode',1,0



PRINT 'Checking table EDIXRefDiscount'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefDiscount' AND COLUMN_NAME='IgnoreMOH1') = 0

BEGIN

    ALTER TABLE EDIXRefDiscount ADD

     IgnoreMOH1               CHAR(2)             NULL,

     IgnoreMOH2               CHAR(2)             NULL,

     IgnoreMOH3               CHAR(2)             NULL

    PRINT 'New column EDIXRefDiscount...IgnoreMOH (11/28/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefDiscount' AND COLUMN_NAME='PercentCFF') = 0

BEGIN

    ALTER TABLE EDIXRefDiscount ADD

     PercentCFF               CHAR(6)             NULL,

     RateCFF                  CHAR(6)             NULL

    PRINT 'New columns EDIXRefDiscount (10/12/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefDiscount' AND COLUMN_NAME='MscTaxCode') = 0

BEGIN

    ALTER TABLE EDIXRefDiscount ADD

     MscTaxCode               CHAR(3)             NULL,

     MscFstCode               CHAR(3)             NULL,

     ChargeCode               CHAR(6)             NULL

    PRINT 'New columns EDIXRefDiscount (08/29/2010)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefDiscount' AND COLUMN_NAME='Rate') = 0

BEGIN

    ALTER TABLE EDIXRefDiscount ADD

     Rate                     CHAR(1)             NULL

    PRINT 'New columns EDIXRefDiscount (01/28/2011)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefDiscount' AND COLUMN_NAME='PercentIsRate') = 0

BEGIN

    ALTER TABLE EDIXRefDiscount ADD

     PercentIsRate            CHAR(1)             NULL

    PRINT 'New column EDIXRefDiscount (07/18/2011)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefDiscount' and COLUMN_NAME='Customer' and CHARACTER_MAXIMUM_LENGTH=7) = 1

BEGIN

  ALTER TABLE EDIXRefDiscount DROP CONSTRAINT EDIXRefDiscountKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefDiscount' and COLUMN_NAME='Customer' and CHARACTER_MAXIMUM_LENGTH=7) = 1

BEGIN

    ALTER TABLE EDIXRefDiscount ALTER COLUMN Customer    CHAR(15) NOT NULL

    ALTER TABLE EDIXRefDiscount ALTER COLUMN Description CHAR(100)

    ALTER TABLE EDIXRefDiscount ALTER COLUMN FixedValue  DECIMAL(14,2)

    ALTER TABLE EDIXRefDiscount ALTER COLUMN GLAccount   CHAR(35) 



  ALTER TABLE EDIXRefDiscount

    ADD CONSTRAINT EDIXRefDiscountKey PRIMARY KEY CLUSTERED

      (

          Partner,

          Customer,

          StockCode,

          Acode

      )

  PRINT 'Change columns EDIXRefDiscount (06/10/2013)'

END

GO



EXEC dbo.CadacusAlterColumn      '07/23/2018','C','EDIXRefDiscount','ProductClass',20,0

EXEC dbo.CadacusAlterColumn      '07/23/2018','C','EDIXRefDiscount','MscTaxCode',3,0

EXEC dbo.CadacusAlterColumn      '07/23/2018','C','EDIXRefDiscount','MscFstCode',3,0

EXEC dbo.CadacusNewColumn        '03/09/2022','N','EDIXRefDiscount','FreightMultiplier',4,2

GO



IF (SELECT  COUNT(*) FROM #CadacusNewColumns where ColumnTable='EDIXRefDiscount' and ColumnName='FreightMultiplier') = 1

BEGIN

  PRINT 'Move values from FixedValue to FreightMultiplier in EDIXRefDiscount (03/09/2022)'

  UPDATE EDIXRefDiscount SET FreightMultiplier=FixedValue, FixedValue=0 WHERE Flag='F' OR Flag='T'

END

GO



PRINT 'Checking table EDIXRefElement'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIXRefElement') = 0

BEGIN

    CREATE TABLE EDIXRefElement(

     Element                  CHAR(5)             NOT NULL,

     Partner                  CHAR(10)            NOT NULL,

     Document                 CHAR(6)             NOT NULL,

     Info                     CHAR(50)            NOT NULL,

     Code                     CHAR(1)             NULL,

     Description              CHAR(40)            NULL,

     Comment                  CHAR(45)            NULL,

     CustomFieldType          CHAR(6)             NULL,

     CustomFieldName          CHAR(6)             NULL,

     ScriptFile               CHAR(100)           NULL,

     ScriptFunction           CHAR(50)            NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIXRefElementKey PRIMARY KEY CLUSTERED

         (

          Element,

          Partner,

          Document,

          Info

         )

    )

    PRINT 'New table EDIXRefElement'

END

GO



PRINT 'Checking table EDIXRefEMailConfig'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefEMailConfig' and COLUMN_NAME='Description' and CHARACTER_MAXIMUM_LENGTH=40) = 1

BEGIN

  ALTER TABLE EDIXRefEMailConfig ALTER COLUMN Description  CHAR(50)

  ALTER TABLE EDIXRefEMailConfig ALTER COLUMN Address      CHAR(255)

  ALTER TABLE EDIXRefEMailConfig ALTER COLUMN EMailCC      CHAR(255)

  ALTER TABLE EDIXRefEMailConfig ALTER COLUMN EMailBCC     CHAR(255)

  ALTER TABLE EDIXRefEMailConfig ALTER COLUMN EMailSubject CHAR(200)

  ALTER TABLE EDIXRefEMailConfig ALTER COLUMN EMailFile    CHAR(200)

  

    PRINT 'Change columns EDIXRefEMailConfig (06/10/2013)'

END

GO



PRINT 'Checking table EDIXRefEMailRoutes'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefEMailRoutes' AND COLUMN_NAME='ErrorCode') = 1

BEGIN

    EXEC sp_rename 'EDIXRefEMailRoutes.ErrorCode',   'IfError',    'COLUMN';

    PRINT 'Change Field in EDIXRefEMailRoutes (03/13/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefEMailRoutes' AND COLUMN_NAME='ErrorFlag') = 0

BEGIN

    ALTER TABLE EDIXRefEMailRoutes ADD ErrorFlag CHAR(1) NULL

    PRINT 'Add column EDIXRefEMailRoutes (07/21/2012)'

END

GO



PRINT 'Checking table EDIXRefEmployees'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefEmployees' AND COLUMN_NAME='Modules') = 0

BEGIN

    ALTER TABLE EDIXRefEmployees ADD Modules char(20) NULL

    PRINT 'Add Modules Field in EDIXRefEmployees (01/26/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefEmployees' AND COLUMN_NAME='HHUtility') = 1

BEGIN

    ALTER TABLE EDIXRefEmployees DROP COLUMN [HHUtility]

    ALTER TABLE EDIXRefEmployees DROP COLUMN [HHShipping]

    ALTER TABLE EDIXRefEmployees DROP COLUMN [HHReceiving]

    ALTER TABLE EDIXRefEmployees DROP COLUMN [HHStockTake]

    ALTER TABLE EDIXRefEmployees DROP COLUMN [HHAfr]

    ALTER TABLE EDIXRefEmployees DROP COLUMN [HHVmi]

    PRINT 'Drop old fields from EDIXRefEmployees (01/26/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefEmployees' and COLUMN_NAME='Employee' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  ALTER TABLE EDIXRefEmployees DROP CONSTRAINT EDIXRefEmployeesKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefEmployees' and COLUMN_NAME='Employee' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  ALTER TABLE EDIXRefEmployees ALTER COLUMN Employee CHAR(20) NOT NULL

  ALTER TABLE EDIXRefEmployees ALTER COLUMN Name     CHAR(50)

  

  ALTER TABLE EDIXRefEmployees

    ADD CONSTRAINT EDIXRefEmployeesKey PRIMARY KEY CLUSTERED

    (

      Employee

    )



  PRINT 'Change columns EDIXRefEmployees (06/10/2013)'

END

GO



--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIXRefEmployees' AND COLUMN_NAME='LanguageCode') = 0

--BEGIN

--    ALTER TABLE EDIXRefEmployees ADD

--     LanguageCode             CHAR(20)            NULL,

--     MenuCode                 CHAR(20)            NULL,

--     SysproOperator           CHAR(20)            NULL,

--     SysproPassword           CHAR(50)            NULL

--    

--    PRINT 'Add new columns in EDIXRefEmployees (11/18/2013)'

--END

--GO



--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIXRefEmployees' AND COLUMN_NAME='Scale') = 0

--BEGIN

--    ALTER TABLE EDIXRefEmployees ADD

--     Scale             CHAR(10)            NULL

--    

--    PRINT 'Add new columns in EDIXRefEmployees (02/09/2016)'

--END

--GO



--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIXRefEmployees' and COLUMN_NAME='Modules' and CHARACTER_MAXIMUM_LENGTH=20) = 1

--BEGIN

--  ALTER TABLE EDIXRefEmployees ALTER COLUMN Modules    CHAR(40)

--END

--GO



EXEC dbo.CadacusNewColumn    '11/18/2013','C','EDIXRefEmployees','LanguageCode',20,0

EXEC dbo.CadacusNewColumn    '11/18/2013','C','EDIXRefEmployees','MenuCode',20,0

EXEC dbo.CadacusNewColumn    '11/18/2013','C','EDIXRefEmployees','SysproOperator',20,0

EXEC dbo.CadacusNewColumn    '11/18/2013','C','EDIXRefEmployees','SysproPassword',50,0

EXEC dbo.CadacusNewColumn    '02/09/2016','C','EDIXRefEmployees','Scale',10,0

EXEC dbo.CadacusAlterColumn  '02/09/2016','C','EDIXRefEmployees','Modules',40,0



PRINT 'Checking table EDIXRefExtendedPrc'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIXRefExtendedPrc') = 1

BEGIN

  DROP TABLE EDIXRefExtendedPrc

  PRINT 'Drop table EDIXRefExtendedPrc (06/10/2013)'

END

GO



PRINT 'Checking table EDIXRefFrghtClass'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIXRefFrghtClass') = 0

BEGIN

    CREATE TABLE EDIXRefFrghtClass(

     Class                    CHAR(10)            NOT NULL,

     ClassNumeric             DECIMAL(4,1)        NULL,

     Description              CHAR(50)            NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIXRefFrghtClassKey PRIMARY KEY CLUSTERED

         (

          Class

         )

    )

    CREATE UNIQUE INDEX EDIXRefFrghtClassIdxNumeric ON EDIXRefFrghtClass(

     ClassNumeric

     )

    PRINT 'New table EDIXRefFrghtClass (12/10/2008)'

END

GO



EXEC dbo.CadacusNewColumn '02/27/2017','N','EDIXRefFrghtClass','PerCubicFootMax',5,2

EXEC dbo.CadacusDropIndex 'EDIXRefFrghtClass', 'PCF', 'Dummy',1    -- Remove uppercase index created by mistake

EXEC dbo.CadacusAddIndex  'EDIXRefFrghtClass', 'Pcf', 'PerCubicFootMax, Class'





IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIXRefFreightClas') = 1

BEGIN

  DROP TABLE EDIXRefFreightClas

  PRINT 'Drop table EDIXRefFreightClas (12/10/2008)'

END

GO



PRINT 'Checking table EDIXRefFrghtItem'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIXRefFrghtItem') = 0

BEGIN

    CREATE TABLE EDIXRefFrghtItem(

     ItemNumber               CHAR(20)            NOT NULL,

     Description              CHAR(50)            NULL,

     Class                    CHAR(10)            NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIXRefFrghtItemKey PRIMARY KEY CLUSTERED

         (

          ItemNumber

         )

    )

    PRINT 'New table EDIXRefFrghtItem'

END

GO



PRINT 'Checking table EDIXRefHandhelds'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIXRefHandhelds') = 1

BEGIN

  DECLARE @UPD NCHAR(100)

  IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefHandhelds' AND COLUMN_NAME='FirstScan') = 0

  BEGIN

    ALTER TABLE EDIXRefHandhelds ADD FirstScan     char(1) NULL

    PRINT 'Add FirstScan option in EDIXRefHandhelds (12/27/2007)'

  END

  IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefHandhelds' AND COLUMN_NAME='RecGLOption') = 0

  BEGIN

    ALTER TABLE EDIXRefHandhelds ADD RecGLOption   char(1) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecGLAccount  char(15) NULL

    PRINT 'Add G/L Receiver Bin/Cost Multiplier options in EDIXRefHandhelds (09/14/2007)'

  END

  IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefHandhelds' AND COLUMN_NAME='ShipInput') = 0

  BEGIN

    ALTER TABLE EDIXRefHandhelds ADD ShipInput    char(1) NULL

    SET @UPD=N'UPDATE EDIXRefHandhelds SET ShipInput=[TextEntry]'

    EXEC sp_executesql @UPD

    ALTER TABLE EDIXRefHandhelds DROP COLUMN [TextEntry]

    ALTER TABLE EDIXRefHandhelds ADD RecInput     char(1) NULL

    ALTER TABLE EDIXRefHandhelds ADD TakeInput    char(1) NULL

    ALTER TABLE EDIXRefHandhelds ADD ShipInputClear char(1) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecInputClear  char(1) NULL

    ALTER TABLE EDIXRefHandhelds ADD TakeInputClear char(1) NULL

    PRINT 'Add Input Flags in EDIXRefHandhelds (08/30/2007)'

  END

  IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefHandhelds' AND COLUMN_NAME='RecBinOption') = 0

  BEGIN

    ALTER TABLE EDIXRefHandhelds ADD RecBinOption char(1) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecBin       char(6) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecSupOption char(1) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecSupplier  char(7) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecRefOption char(1) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecReference char(9) NULL

    PRINT 'Add Receiver Bin/Cost Multiplier options in EDIXRefHandhelds (08/17/2007)'

  END

  IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefHandhelds' AND COLUMN_NAME='RecColWhse') = 0

  BEGIN

    ALTER TABLE EDIXRefHandhelds ADD RecColOrder decimal(1,0) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecColStk decimal(1,0) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecColBin decimal(1,0) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecColQty decimal(1,0) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecColWhse decimal(1,0) NULL

    PRINT 'Add Receiver View Columns in EDIXRefHandhelds (08/08/2007)'

  END

  IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefHandhelds' AND COLUMN_NAME='ShipColWhse') = 0

  BEGIN

    ALTER TABLE EDIXRefHandhelds ADD ShipColOrder decimal(1,0) NULL

    ALTER TABLE EDIXRefHandhelds ADD ShipColStk decimal(1,0) NULL

    ALTER TABLE EDIXRefHandhelds ADD ShipColBin decimal(1,0) NULL

    ALTER TABLE EDIXRefHandhelds ADD ShipColQty decimal(1,0) NULL

    ALTER TABLE EDIXRefHandhelds ADD ShipColWhse decimal(1,0) NULL

    SET @UPD=N'UPDATE EDIXRefHandhelds SET ShipColOrder=CONVERT(int,[ColumnOrder])'

    EXEC sp_executesql @UPD

    ALTER TABLE EDIXRefHandhelds DROP COLUMN [ColumnOrder]

    SET @UPD=N'UPDATE EDIXRefHandhelds SET ShipColStk=CONVERT(int,[ColumnItem])'

    EXEC sp_executesql @UPD

    ALTER TABLE EDIXRefHandhelds DROP COLUMN [ColumnItem]

    SET @UPD=N'UPDATE EDIXRefHandhelds SET ShipColBin=CONVERT(int,[ColumnBin])'

    EXEC sp_executesql @UPD

    ALTER TABLE EDIXRefHandhelds DROP COLUMN [ColumnBin]

    SET @UPD=N'UPDATE EDIXRefHandhelds SET ShipColQty=CONVERT(int,[ColumnQuantity])'

    EXEC sp_executesql @UPD

    ALTER TABLE EDIXRefHandhelds DROP COLUMN [ColumnQuantity]

    PRINT 'Add/Rename Shipment View Columns in EDIXRefHandhelds (08/08/2007)'

  END

  IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefHandhelds' AND COLUMN_NAME='ShipXFlag') = 0

  BEGIN

    ALTER TABLE EDIXRefHandhelds ADD ShipXFlag char(1) NULL

    ALTER TABLE EDIXRefHandhelds ADD ShipXOption char(1) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecXFlag char(1) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecXOption char(1) NULL

    ALTER TABLE EDIXRefHandhelds ADD TakeXFlag char(1) NULL

    ALTER TABLE EDIXRefHandhelds ADD TakeXOption char(1) NULL

    SET @UPD=N'UPDATE EDIXRefHandhelds SET ShipXOption=[XOption]'

    EXEC sp_executesql @UPD

    ALTER TABLE EDIXRefHandhelds DROP COLUMN [XOption]

    PRINT 'Add X Option columns to EDIXRefHandhelds (07/02/2007)'

  END

  IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefHandhelds' AND COLUMN_NAME='RecPost') = 0

  BEGIN

    ALTER TABLE EDIXRefHandhelds ADD RecPost char(1) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecCreate char(1) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecWhse1 char(2) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecWhse2 char(2) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecWhse3 char(2) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecWhse4 char(2) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecWhse5 char(2) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecReport char(1) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecPrinter char(20) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecShortage char(1) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecOverage char(1) NULL

    ALTER TABLE EDIXRefHandhelds ADD RecOveragePct decimal(2,0) NULL

    PRINT 'Add new receiving columns to EDIXRefHandhelds'

  END

  IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefHandhelds' AND COLUMN_NAME='TakeCreate') = 0

  BEGIN

    ALTER TABLE EDIXRefHandhelds ADD TakeCreate char(1) NULL

    ALTER TABLE EDIXRefHandhelds ADD TakePost char(1) NULL

    ALTER TABLE EDIXRefHandhelds ADD TakeReport char(1) NULL

    ALTER TABLE EDIXRefHandhelds ADD TakePrinter char(20) NULL

    PRINT 'Add new Take columns to EDIXRefHandhelds'

  END

  IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefHandhelds' AND COLUMN_NAME='POQuantity') = 1

  BEGIN

    ALTER TABLE EDIXRefHandhelds ADD RecQuantity char(1) NULL

    SET @UPD=N'UPDATE EDIXRefHandhelds SET RecQuantity=[POQuantity]'

    EXEC sp_executesql @UPD

    ALTER TABLE EDIXRefHandhelds DROP COLUMN [POQuantity]

    PRINT 'Rename column EDIXRefHandhelds..POQuantity'

  END

  IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefHandhelds' AND COLUMN_NAME='NetworkCreate') = 1

  BEGIN

    ALTER TABLE EDIXRefHandhelds ADD ShipCreate char(1) NULL

    SET @UPD=N'UPDATE EDIXRefHandhelds SET ShipCreate=[NetworkCreate]'

    EXEC sp_executesql @UPD

    ALTER TABLE EDIXRefHandhelds DROP COLUMN [NetworkCreate]

    PRINT 'Rename column EDIXRefHandhelds..NetworkCreate'

  END

  IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefHandhelds' AND COLUMN_NAME='NetworkPost') = 1

  BEGIN

    ALTER TABLE EDIXRefHandhelds ADD ShipPost char(1) NULL

    SET @UPD=N'UPDATE EDIXRefHandhelds SET ShipPost=[NetworkPost]'

    EXEC sp_executesql @UPD

    ALTER TABLE EDIXRefHandhelds DROP COLUMN [NetworkPost]

    PRINT 'Rename column EDIXRefHandhelds..NetworkPost'

  END

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIXRefHandhelds') = 1

BEGIN

  IF ( SELECT COUNT(*) FROM EDIXRefHandhelds ) > 0

   BEGIN

    PRINT '-----'

    PRINT 'Conversion required on Handheld Configurations'

    PRINT 'Run Handheld Configuration Cross-Reference to perform conversion'

    PRINT '-----'

   END

  ELSE

   BEGIN

    DROP TABLE EDIXRefHandhelds

    PRINT 'Drop table EDIXRefHandhelds (12/11/2008)'

   END

END

GO



PRINT 'Checking table EDIXRefInputSort'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIXRefInputSort') = 0

BEGIN

    CREATE TABLE EDIXRefInputSort(

     Partner                  CHAR(10)            NOT NULL,

     Country                  CHAR(2)             NOT NULL,

     PostalStart              CHAR(15)            NOT NULL,

     PostalEnd                CHAR(15)            NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIXRefInputSortKey PRIMARY KEY CLUSTERED

         (

          Partner,

          Country,

          PostalStart

         )

    )

    PRINT 'New table EDIXRefInputSort'

END

GO



PRINT 'Checking table EDIXRefLabel'

GO



--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIXRefLabel' AND COLUMN_NAME='UPCType') = 0

--BEGIN

--    ALTER TABLE EDIXRefLabel ADD 

--     UPCType                  CHAR(1)             NULL

--    PRINT 'Add new column to EDIXRefLabel  (05/01/2008)'

--END

--GO

--

--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIXRefLabel' AND COLUMN_NAME='NextSequential') = 0

--BEGIN

--    ALTER TABLE EDIXRefLabel ADD 

--     NextSequential        DECIMAL(9,0)          NULL

--    PRINT 'Add new column to EDIXRefLabel  (08/21/2009)'

--END

--GO

--

--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIXRefLabel' AND COLUMN_NAME='UCCOverride') = 0

--BEGIN

--    ALTER TABLE EDIXRefLabel ADD 

--     UCCOverride              DECIMAL(7,0)        NULL

--    PRINT 'Add new column to EDIXRefLabel  (02/22/2010)'

--END

--GO

--

--IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

--    WHERE TABLE_NAME='EDIXRefLabel' AND COLUMN_NAME='LabelEngine') = 0

--BEGIN

--    ALTER TABLE EDIXRefLabel ADD

--     LabelEngine          CHAR(1)             NULL

--    PRINT 'New column EDIXRefLabel (08/30/2016)'

--END

--GO



EXEC dbo.CadacusNewColumn        '05/01/2008','C','EDIXRefLabel','UPCType',1,0

EXEC dbo.CadacusNewColumn        '08/21/2009','N','EDIXRefLabel','NextSequential',9,0

EXEC dbo.CadacusNewColumn        '02/22/2010','N','EDIXRefLabel','UCCOverride',12,0

EXEC dbo.CadacusNewColumn        '08/30/2016','C','EDIXRefLabel','LabelEngine',1,0

EXEC dbo.CadacusNewColumn        '03/06/2018','N','EDIXRefLabel','SSCCDigits',2,0



EXEC dbo.CadacusAlterColumn      '03/06/2018','N','EDIXRefLabel','UCCOverride',12,0



PRINT 'Checking table EDIXRefLists'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIXRefLists') = 0

BEGIN

    CREATE TABLE EDIXRefLists(

     ListCode                 CHAR(30)            NOT NULL,

     Code                     CHAR(50)            NOT NULL,

     Description              CHAR(100)           NULL,

     Extra                    CHAR(50)            NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIXRefListsKey PRIMARY KEY CLUSTERED

         (

          ListCode,

          Code

         )

    )

    PRINT 'New table EDIXRefLists (01/29/2018)'

END

GO



PRINT 'Checking table EDIXRefLocation'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefLocation' AND COLUMN_NAME='Name') = 0

BEGIN

    ALTER TABLE EDIXRefLocation ADD

     Name                     CHAR(60)            NULL,

     Address1                 CHAR(60)            NULL,

     Address2                 CHAR(60)            NULL,

     Address3                 CHAR(60)            NULL,

     Address4                 CHAR(60)            NULL,

     City                     CHAR(30)            NULL,

     State                    CHAR(2)             NULL,

     Zip                      CHAR(15)            NULL

    PRINT 'New address columns EDIXRefLocation (12/04/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefLocation' AND COLUMN_NAME='TransType') = 0

BEGIN

    ALTER TABLE EDIXRefLocation ADD

     TransType                CHAR(2)            NULL

    PRINT 'New address columns EDIXRefLocation (02/03/2013)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefLocationOld') > 0

BEGIN

    PRINT 'Drop Old Table EDIXrefLocationOld'

    PRINT 'If this command fails, ignore it or remove the table manually.'    

    DROP TABLE [dbo].[EDIXRefLocationOld]

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefLocation' and COLUMN_NAME='Location' and CHARACTER_MAXIMUM_LENGTH=35) = 1

BEGIN

  ALTER TABLE EDIXRefLocation DROP CONSTRAINT EDIXRefLocationKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefLocation' and COLUMN_NAME='Location' and CHARACTER_MAXIMUM_LENGTH=35) = 1

BEGIN

  DROP INDEX EDIXRefLocation.EDIXRefLocationIdxCus

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefLocation' and COLUMN_NAME='Location' and CHARACTER_MAXIMUM_LENGTH=35) = 1

BEGIN

    ALTER TABLE EDIXRefLocation ALTER COLUMN Location    CHAR(50) NOT NULL

    ALTER TABLE EDIXRefLocation ALTER COLUMN Customer    CHAR(15)

    ALTER TABLE EDIXRefLocation ALTER COLUMN Address     CHAR(20)

    ALTER TABLE EDIXRefLocation ALTER COLUMN Warehouse   CHAR(10)

    ALTER TABLE EDIXRefLocation ALTER COLUMN ShipVia     CHAR(50)

    ALTER TABLE EDIXRefLocation ADD          ShipViaCode CHAR(6)  

    ALTER TABLE EDIXRefLocation ALTER COLUMN Branch      CHAR(10)

    ALTER TABLE EDIXRefLocation ALTER COLUMN OutgoingShipVia CHAR(50)

    ALTER TABLE EDIXRefLocation ADD          OutgoingViaCode CHAR(6) 

    ALTER TABLE EDIXRefLocation ALTER COLUMN PriceCode   CHAR(10)

  ALTER TABLE EDIXRefLocation

    ADD CONSTRAINT EDIXRefLocationKey PRIMARY KEY CLUSTERED

    (

           Partner,

           Location

    )

  CREATE UNIQUE INDEX EDIXRefLocationIdxCus ON EDIXRefLocation(

    Customer,

    Address,

    Partner,

    Location

    )

    PRINT 'Change columns EDIXRefLocation (06/10/2013)'

END

GO



EXEC dbo.CadacusNewColumn '07/16/2021','C','EDIXRefLocation','ShipDaysFlag',1,0

EXEC dbo.CadacusNewColumn '07/16/2021','C','EDIXRefLocation','ShipDays',7,0



PRINT 'Checking table EDIXRefOrder'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefOrder' AND COLUMN_NAME='LastCumesDate') = 0

BEGIN

    ALTER TABLE EDIXRefOrder ADD LastCumesDate datetime NULL

    PRINT 'New column EDIXRefOrder..LastCumesDate'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefOrder' AND COLUMN_NAME='LastCumesValue') = 0

BEGIN

    ALTER TABLE EDIXRefOrder ADD LastCumesValue decimal(10,3) NULL

    PRINT 'New column EDIXRefOrder..LastCumesValue'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefOrder' and COLUMN_NAME='SalesOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  ALTER TABLE EDIXRefOrder DROP CONSTRAINT EDIXRefOrderKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefOrder' and COLUMN_NAME='SalesOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  DROP INDEX EDIXRefOrder.EDIXRefOrderIdxCustomer

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefOrder' and COLUMN_NAME='SalesOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

  DROP INDEX EDIXRefOrder.EDIXRefOrderIdxOrder

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefOrder' and COLUMN_NAME='SalesOrder' and CHARACTER_MAXIMUM_LENGTH=6) = 1

BEGIN

    ALTER TABLE EDIXRefOrder ALTER COLUMN SalesOrder     CHAR(20)

    ALTER TABLE EDIXRefOrder ALTER COLUMN CumesDate      DATETIME

    ALTER TABLE EDIXRefOrder ALTER COLUMN CumesValue     DECIMAL(18,6)

    ALTER TABLE EDIXRefOrder ALTER COLUMN LastCumesValue DECIMAL(18,6)



 ALTER TABLE EDIXRefOrder

   ADD CONSTRAINT EDIXRefOrderKey PRIMARY KEY CLUSTERED

   (

          Partner,

          StockCode,

          Location,

          KeyPurchaseOrder

   )

 

 CREATE UNIQUE INDEX EDIXRefOrderIdxCustomer ON EDIXRefOrder(

  Partner,

  CustomerCode,

  Location,

  KeyPurchaseOrder

  )

 

 CREATE UNIQUE INDEX EDIXRefOrderIdxOrder ON EDIXRefOrder(

  SalesOrder,

  StockCode

  )



    PRINT 'Change columns EDIXrefOrder (06/10/2013)'

END

GO



PRINT 'Checking table EDIXRefPKGInstruct'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefPKGInstruct' AND COLUMN_NAME='DescriptionFlag') = 0

BEGIN

    ALTER TABLE EDIXRefPKGInstruct ADD

     DescriptionFlag          CHAR(1)             NULL,

     ReportFlag               CHAR(1)             NULL,

     CommentFlag              CHAR(1)             NULL,

     CFName                   CHAR(6)             NULL

    PRINT 'New columns EDIXRefPKGInstruct (05/26/2010)'

END

GO



PRINT 'Checking table EDIXRefPrinters'

GO



EXEC dbo.CadacusNewColumn '02/04/2008','C','EDIXRefPrinters','Method',1,0

EXEC dbo.CadacusNewColumn '07/23/2019','C','EDIXRefPrinters','Handheld',1,0



PRINT 'Checking table EDIXRefPrintersSel'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIXRefPrinterSel') = 0

BEGIN

    CREATE TABLE EDIXRefPrinterSel(

     Device                   CHAR(30)            NOT NULL,

     Operator                 CHAR(20)            NOT NULL,

     Station                  CHAR(10)            NOT NULL,

     Scac                     CHAR(4)             NOT NULL,

     Service                  CHAR(10)            NOT NULL,

     Description              CHAR(50)            NULL,

     Code                     CHAR(10)            NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIXRefPrinterSelKey PRIMARY KEY CLUSTERED

         (

          Device,

          Operator,

          Station,

          Scac,

          Service

         )

    )

    PRINT 'New table EDIXRefPrinterSel (02/16/2018)'

END

GO



EXEC dbo.CadacusNewColumn '04/20/2018','C','EDIXRefPrinterSel','Account',20,0

EXEC dbo.CadacusNewColumn '08/21/2018','C','EDIXRefPrinterSel','DocPrinter',60,0

EXEC dbo.CadacusNewColumn '10/06/2018','N','EDIXRefPrinterSel','DocCopies',2,0



PRINT 'Checking table EDIXRefProduct '

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefProduct' AND COLUMN_NAME='LeaveBlank') = 0

BEGIN

    ALTER TABLE EDIXRefProduct ADD LeaveBlank char(1)  NULL

    PRINT 'Add LeaveBlank column to EDIXRefProduct (05/17/2007)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefProduct' AND COLUMN_NAME='ScriptFile') = 0

BEGIN

    ALTER TABLE EDIXRefProduct ADD

     ScriptFile               CHAR(100)           NULL,

     ScriptFunction           CHAR(50)            NULL

    PRINT 'New Scripting columns EDIXRefProduct (01/17/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefProduct' AND COLUMN_NAME='ScriptFlag') = 0

BEGIN

    ALTER TABLE EDIXRefProduct ADD

     ScriptFlag            CHAR(1)             NULL,

     ScriptCheck           CHAR(50)            NULL

    PRINT 'New Scripting columns EDIXRefProduct (10/12/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefProduct' AND COLUMN_NAME='CFFQual') = 0

BEGIN

    ALTER TABLE EDIXRefProduct ADD

     CFFQual                  CHAR(1)             NULL

    PRINT 'New column EDIXRefProduct (07/06/2010)'

END

GO



PRINT 'Checking table EDIXRefPromotions'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIXrefPromotions') = 1

BEGIN

  IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIXRefPromotions') = 1

   BEGIN

    DROP TABLE EDIXrefPromotions

    PRINT 'drop EDIXrefPromotions (EDIXRefPromotions is correct table name) (12/10/2008)'

   END

  ELSE

   BEGIN

    EXEC sp_rename 'EDIXrefPromotions', 'EDIXRefPromotions' ;

    EXEC sp_rename 'EDIXRefPromotions.EDIXrefPromotionsKey', 'EDIXRefPromotionsKey';

    PRINT 'Correct table name - EDIXRefPromotions (12/10/2008)'

   END

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefPromotions' and COLUMN_NAME='Account' and CHARACTER_MAXIMUM_LENGTH=7) = 1

BEGIN

  ALTER TABLE EDIXRefPromotions DROP CONSTRAINT EDIXRefPromotionsKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefPromotions' and COLUMN_NAME='Account' and CHARACTER_MAXIMUM_LENGTH=7) = 1

BEGIN

    ALTER TABLE EDIXRefPromotions ALTER COLUMN Account           CHAR(15) NOT NULL

    ALTER TABLE EDIXRefPromotions ALTER COLUMN Location          CHAR(20) NOT NULL

    ALTER TABLE EDIXRefPromotions ALTER COLUMN ProductClass      CHAR(20)

    ALTER TABLE EDIXRefPromotions ALTER COLUMN ChargeDescription CHAR(100)

    ALTER TABLE EDIXRefPromotions ALTER COLUMN PromotionValue    DECIMAL(15,5)



 ALTER TABLE EDIXRefPromotions

   ADD CONSTRAINT EDIXRefPromotionsKey PRIMARY KEY CLUSTERED

   (

          Account,

          Location,

          StockCode,

          ChargeCode

   )



    PRINT 'Change columns EDIXRefPromotions (06/10/2013)'

END

GO



PRINT 'Checking table EDIXRefQuestions'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefQuestions' AND COLUMN_NAME='CFFType') = 0

BEGIN

    ALTER TABLE EDIXRefQuestions ADD

     CFFType                  CHAR(6)             NULL,

     CFFName                  CHAR(6)             NULL

    PRINT 'New columns EDIXRefQuestions (08/27/2010)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefQuestions' AND COLUMN_NAME='Required') = 0

BEGIN

    ALTER TABLE EDIXRefQuestions ADD

     Required                 CHAR(1)             NULL

    PRINT 'New columns EDIXRefQuestions (05/11/2011)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefQuestions' and COLUMN_NAME='Customer' and CHARACTER_MAXIMUM_LENGTH=10) = 1

BEGIN

  ALTER TABLE EDIXRefQuestions DROP CONSTRAINT EDIXRefQuestionsKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefQuestions' and COLUMN_NAME='Customer' and CHARACTER_MAXIMUM_LENGTH=10) = 1

BEGIN

    ALTER TABLE EDIXRefQuestions ALTER COLUMN Customer          CHAR(15) NOT NULL



 ALTER TABLE EDIXRefQuestions

   ADD CONSTRAINT EDIXRefQuestionsKey PRIMARY KEY CLUSTERED

   (

          Type,

          Customer,

          Line

   )



    PRINT 'Change columns EDIXRefQuestions (06/10/2013)'

END

GO



PRINT 'Checking table EDIXRefReference'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefReference' AND COLUMN_NAME='DateFlag') = 0

BEGIN

    ALTER TABLE EDIXRefReference ADD

     DateFlag                CHAR(1)             NULL,

     TimeFlag                CHAR(1)             NULL

    PRINT 'New columns EDIXRefReference (03/30/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefReference' AND COLUMN_NAME='PERFlag') = 0

BEGIN

    ALTER TABLE EDIXRefReference ADD

     PERFlag                CHAR(1)             NULL

    PRINT 'New columns EDIXRefReference (12/17/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefReference' AND COLUMN_NAME='ScriptFile') = 0

BEGIN

    ALTER TABLE EDIXRefReference ADD

     ScriptFile               CHAR(100)           NULL,

     ScriptFunction           CHAR(50)            NULL

    PRINT 'New Scripting columns EDIXRefReference (01/17/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefReference' AND COLUMN_NAME='N1LoopFlag') = 0

BEGIN

    ALTER TABLE EDIXRefReference ADD

     N1LoopFlag                CHAR(1)             NULL

    PRINT 'New columns EDIXRefReference (10/23/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefReference' AND COLUMN_NAME='DTMQualifier') = 0

BEGIN

    ALTER TABLE EDIXRefReference ADD

     DTMQualifier             CHAR(3)             NULL

    PRINT 'New columns EDIXRefReference (10/18/2010)'

END

GO





PRINT 'Checking table EDIXRefSalesman'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefSalesman' and COLUMN_NAME='Salesman' and CHARACTER_MAXIMUM_LENGTH=3) = 1

BEGIN

  ALTER TABLE EDIXRefSalesman DROP CONSTRAINT EDIXRefSalesmanKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefSalesman' and COLUMN_NAME='Salesman' and CHARACTER_MAXIMUM_LENGTH=3) = 1

BEGIN

  DROP INDEX EDIXRefSalesman.EDIXRefSalesmanIdxSalesman

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefSalesman' and COLUMN_NAME='Salesman' and CHARACTER_MAXIMUM_LENGTH=3) = 1

BEGIN

    ALTER TABLE EDIXRefSalesman ALTER COLUMN Salesman  CHAR(20)



 ALTER TABLE EDIXRefSalesman

   ADD CONSTRAINT EDIXRefSalesmanKey PRIMARY KEY CLUSTERED

   (

          Partner,

          Code

   )

 

 CREATE UNIQUE INDEX EDIXRefSalesmanIdxSalesman ON EDIXRefSalesman(

  Salesman,

  Partner

  )



    PRINT 'Change columns EDIXRefSalesman (06/10/2013)'

END

GO



PRINT 'Checking table EDIXRefSCAC'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefSCAC' AND COLUMN_NAME='CarrierQualifier') = 0

BEGIN

    ALTER TABLE EDIXRefSCAC ADD CarrierQualifier char(2) NULL

    PRINT 'Add new column EDIXRefSCAC..CarrierQualifier'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefSCAC' AND COLUMN_NAME='ServiceLevelCode1') = 0

BEGIN

    ALTER TABLE EDIXRefSCAC ADD 

     ServiceLevelCode1        CHAR(2)             NULL

    PRINT 'Add new column to EDIXRefSCAC (05/28/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefSCAC' AND COLUMN_NAME='ReturnService') = 0

BEGIN

    ALTER TABLE EDIXRefSCAC ADD 

     ReturnService            CHAR(1)             NULL,

     VerbalConfirm            CHAR(1)             NULL

    PRINT 'Add new columns to EDIXRefSCAC (08/25/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefSCAC' AND COLUMN_NAME='BillingOverride') = 0

BEGIN

    ALTER TABLE EDIXRefSCAC ADD 

     BillingOverride           CHAR(1)             NULL

    PRINT 'Add new column to EDIXRefSCAC (12/15/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefSCAC' AND COLUMN_NAME='CADQualifier') = 0

BEGIN

    ALTER TABLE EDIXRefSCAC ADD 

     CADQualifier             CHAR(3)             NULL

    PRINT 'Add new column to EDIXRefSCAC (05/13/2010)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefSCAC' AND COLUMN_NAME='AOMFlag') = 0

BEGIN

    ALTER TABLE EDIXRefSCAC ADD 

     AOMFlag                  CHAR(1)             NULL,

     AOMShipFlag              CHAR(1)             NULL

    PRINT 'Add new column to EDIXRefSCAC (08/28/2011)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefSCAC' AND COLUMN_NAME='Routing') = 0

BEGIN

    ALTER TABLE EDIXRefSCAC ADD 

    Routing                  CHAR(35)            NULL

    PRINT 'Add new column to EDIXRefSCAC (10/17/2011)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefSCAC' AND COLUMN_NAME='Multiplier') = 0

BEGIN

    ALTER TABLE EDIXRefSCAC ADD 

     Multiplier               DECIMAL(6,4)        NULL,

     CostMultiplier           DECIMAL(6,4)        NULL

    PRINT 'Add new column to EDIXRefSCAC (05/28/2012)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefSCAC' AND COLUMN_NAME='AltServiceFlag') = 0

BEGIN

    ALTER TABLE EDIXRefSCAC ADD 

     AltServiceFlag           CHAR(1)             NULL,

     AltService               CHAR(10)            NULL

    PRINT 'Add new column to EDIXRefSCAC (05/16/2013)'

END

GO





PRINT 'Checking table EDIXRefScripts'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIXRefScripts') = 0

BEGIN

    CREATE TABLE EDIXRefScripts(

     ScriptModule             DECIMAL(5,0)        NOT NULL,

     ScriptAction             DECIMAL(5,0)        NOT NULL,

     Code                     CHAR(20)            NOT NULL,

     Description              CHAR(100)           NULL,

     ScriptFile               CHAR(100)           NULL,

     ScriptFunction           CHAR(50)            NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIXRefScriptsKey PRIMARY KEY CLUSTERED

         (

          ScriptModule,

          ScriptAction,

          Code

         )

    )

    PRINT 'Add table EDIXRefScripts (09/24/2014)'

END

GO



PRINT 'Checking table EDIXRefSegmentRpt'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIXRefSegmentRpt') = 0

BEGIN

    CREATE TABLE EDIXRefSegmentRpt(

     Partner                  CHAR(10)            NOT NULL,

     Document                 CHAR(6)             NOT NULL,

     Line                     DECIMAL(5,0)        NOT NULL,

     Info                     CHAR(5)             NULL,

     Element                  DECIMAL(2,0)        NULL,

     Position1                DECIMAL(2,0)        NULL,

     Qualifier1               CHAR(20)            NULL,

     Position2                DECIMAL(2,0)        NULL,

     Qualifier2               CHAR(20)            NULL,

     Length                   DECIMAL(2,0)        NULL,

     Title                    CHAR(30)            NULL,

     Quote                    CHAR(1)             NULL,

     IsDetail                 CHAR(1)             NULL,

     IsDate                   CHAR(1)             NULL,

     Decimals                 DECIMAL(1,0)        NULL,

     Justify                  CHAR(1)             NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIXRefSegmentRptKey PRIMARY KEY CLUSTERED

         (

          Partner,

          Document,

          Line

         )

    )

    PRINT 'New table EDIXRefSegmentRpt (07/20/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefSegmentRpt' AND COLUMN_NAME='Required') = 0

BEGIN

    ALTER TABLE EDIXRefSegmentRpt ADD Required CHAR(1) NULL

    PRINT 'New column EDIXRefSegmentRpt..Required (08/23/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefSegmentRpt' AND COLUMN_NAME='ReportDecimals') = 0

BEGIN

    ALTER TABLE EDIXRefSegmentRpt ADD 

     ReportDecimals           DECIMAL(1,0)        NULL,

     IsNumeric                CHAR(1)             NULL

    PRINT 'New columns EDIXRefSegmentRpt (06/19/2010)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefSegmentRpt' AND COLUMN_NAME='Multiple') = 0

BEGIN

    ALTER TABLE EDIXRefSegmentRpt ADD 

     Multiple                 CHAR(1)             NULL

    PRINT 'New column EDIXRefSegmentRpt..Multiple (06/19/2010)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefSegmentRpt' AND COLUMN_NAME='Fixed') = 0

BEGIN

    ALTER TABLE EDIXRefSegmentRpt ADD 

     Fixed                    CHAR(50)            NULL

    PRINT 'New column EDIXRefSegmentRpt (07/08/2004)'

END

GO



PRINT 'Checking table EDIXRefServices'

GO



EXEC dbo.CadacusNewColumn        '08/25/2008','C','EDIXRefServices','Verbal',1,0

EXEC dbo.CadacusNewColumn        '01/29/2018','C','EDIXRefServices','PackLabels',1,0



PRINT 'Checking table EDIXRefShipVia'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefShipVia' and COLUMN_NAME='ShipVia' and CHARACTER_MAXIMUM_LENGTH=30) = 1

BEGIN

    ALTER TABLE EDIXRefShipVia ALTER COLUMN ShipVia     CHAR(50)

    ALTER TABLE EDIXRefShipVia ADD          ShipViaCode CHAR(6)

    PRINT 'Change columns EDIXRefShipVia (06/10/2013)'

END

GO



PRINT 'Checking table EDIXRefSpecial'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefSpecial' and COLUMN_NAME='Customer' and CHARACTER_MAXIMUM_LENGTH=7) = 1

BEGIN

  ALTER TABLE EDIXRefSpecial DROP CONSTRAINT EDIXRefSpecialKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefSpecial' and COLUMN_NAME='Customer' and CHARACTER_MAXIMUM_LENGTH=7) = 1

BEGIN

    ALTER TABLE EDIXRefSpecial ALTER COLUMN Customer    CHAR(15) NOT NULL

 ALTER TABLE EDIXRefSpecial

   ADD CONSTRAINT EDIXRefSpecialKey PRIMARY KEY CLUSTERED

   (

          Special,

          Customer

   )

    PRINT 'Change columns EDIXRefSpecial (06/10/2013)'

END

GO



PRINT 'Checking table EDIXRefStationAR'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefStationAR' and COLUMN_NAME='Customer' and CHARACTER_MAXIMUM_LENGTH=7) = 1

BEGIN

  ALTER TABLE EDIXRefStationAR DROP CONSTRAINT EDIXRefStationARKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefStationAR' and COLUMN_NAME='Customer' and CHARACTER_MAXIMUM_LENGTH=7) = 1

BEGIN

  DROP INDEX EDIXRefStationAR.EDIXRefStationARIdxCus

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefStationAR' and COLUMN_NAME='Customer' and CHARACTER_MAXIMUM_LENGTH=7) = 1

BEGIN

    ALTER TABLE EDIXRefStationAR ALTER COLUMN Customer          CHAR(15) NOT NULL



 ALTER TABLE EDIXRefStationAR

   ADD CONSTRAINT EDIXRefStationARKey PRIMARY KEY CLUSTERED

   (

          Station,

          Customer

   )

 

 CREATE UNIQUE INDEX EDIXRefStationARIdxCus ON EDIXRefStationAR(

  Customer,

  Station

  )



    PRINT 'Change columns EDIXRefStationAR (06/10/2013)'

END

GO



PRINT 'Checking table EDIXRefStockSub'

GO



IF (dbo.CadacusIndexTest('EDIXRefStockSubIdxSub') = 0)

BEGIN

    CREATE UNIQUE INDEX EDIXRefStockSubIdxSub ON EDIXRefStockSub(

     Substitute,

     Partner,

     StockCode,

     Attribute

     )

  PRINT 'Adding Index EDIXRefStockSubIdxSub (04/17/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefStockSub' AND COLUMN_NAME='StartDate') = 0

BEGIN

    ALTER TABLE EDIXRefStockSub ADD

     StartDate                DATETIME            NULL,

     EndDate                  DATETIME            NULL

    PRINT 'Add date columns EDIXRefStockSub (07/21/2012)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefStockSub' AND COLUMN_NAME='SdateDate') = 1

BEGIN

    DECLARE @UPD NCHAR(500)

    SET @UPD=N'UPDATE EDIXRefStockSub SET StartDate=SDateCentury + SdateDate WHERE SdateDate > ''000000'''

    EXEC sp_executesql @UPD

    SET @UPD=N'UPDATE EDIXRefStockSub SET EndDate=EdateCentury + EdateDate   WHERE EdateDate > ''000000'''

    EXEC sp_executesql @UPD

    SET @UPD=N'ALTER TABLE EDIXRefStockSub DROP COLUMN SDateCentury, SdateDate, EdateCentury, EdateDate'

    EXEC sp_executesql @UPD

    PRINT 'Convert date columns EDIXRefStockSub (07/21/2012)'

END

GO



PRINT 'Checking table EDIXRefTariff'

GO



--  Add new 'EDIXRefTariff' Table

IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIXRefTariff') = 0

BEGIN

    CREATE TABLE EDIXRefTariff(

     Code                     CHAR(20)            NOT NULL,

     Country                  CHAR(3)             NOT NULL,

     TariffCode               CHAR(20)            NULL,

     Description              CHAR(100)           NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIXRefTariffKey PRIMARY KEY CLUSTERED

         (

          Code,

          Country

         )

    )

    PRINT 'New table EDIXRefTariff (01/23/2018)'

END

GO





PRINT 'Checking table EDIXRefUOM'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefUOM' AND COLUMN_NAME='ConvFact') = 0

BEGIN

    ALTER TABLE EDIXRefUOM ADD ConvFact    DECIMAL(10,6)       NULL

    ALTER TABLE EDIXRefUOM ADD ConvMulDiv  CHAR(1)             NULL

    PRINT 'Add Fields in EDIXRefUOM (06/26/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefUOM' AND COLUMN_NAME='Direction') = 0

BEGIN

    ALTER TABLE EDIXRefUOM ADD Direction  CHAR(1)             NULL

    PRINT 'Add Fields in EDIXRefUOM (07/21/2009)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefUOM' and COLUMN_NAME='UnitOfMeasure' and CHARACTER_MAXIMUM_LENGTH=3) = 1

BEGIN

  ALTER TABLE EDIXRefUOM DROP CONSTRAINT EDIXRefUOMKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefUOM' and COLUMN_NAME='UnitOfMeasure' and CHARACTER_MAXIMUM_LENGTH=3) = 1

BEGIN

  DROP INDEX EDIXRefUOM.EDIXRefUOMIdxCode

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefUOM' and COLUMN_NAME='UnitOfMeasure' and CHARACTER_MAXIMUM_LENGTH=3) = 1

BEGIN

    ALTER TABLE EDIXRefUOM ALTER COLUMN UnitOfMeasure CHAR(10) NOT NULL

    ALTER TABLE EDIXRefUOM ALTER COLUMN ConvFact      DECIMAL(12,6)



 

 ALTER TABLE EDIXRefUOM

   ADD CONSTRAINT EDIXRefUOMKey PRIMARY KEY CLUSTERED

   (

          UnitOfMeasure,

          Partner,

          Stock,

          EDICode

   )

 

 CREATE UNIQUE INDEX EDIXRefUOMIdxCode ON EDIXRefUOM(

  EDICode,

  Partner,

  Stock,

  UnitOfMeasure

  )



    PRINT 'Change columns EDIXRefUOM (06/10/2013)'

END

GO



PRINT 'Checking table EDIXRefUPC'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefUPC' AND COLUMN_NAME='Partner') = 0

BEGIN

  IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE

		WHERE TABLE_NAME='EDIXRefUPC' AND CONSTRAINT_NAME='EDIXRefUPCKey') = 1

  BEGIN

    ALTER TABLE EDIXRefUPC DROP CONSTRAINT EDIXRefUPCKey

  END

  IF (dbo.CadacusIndexTest('EDIXRefUPCIdxCode') = 1)

  BEGIN

    DROP INDEX EDIXRefUPC.EDIXRefUPCIdxCode

  END

  ALTER TABLE EDIXRefUPC ADD Partner CHAR(10) NOT NULL DEFAULT SPACE(10)

  ALTER TABLE EDIXRefUPC

    ADD CONSTRAINT EDIXRefUPCKey PRIMARY KEY CLUSTERED

         (

          StockCode,

          Partner,

          Code,

          UnitOfMeasure

         )

  CREATE UNIQUE INDEX EDIXRefUPCIdxCode ON EDIXRefUPC

    (

     Code,

     Partner,

     StockCode,

     UnitOfMeasure

    )

  PRINT 'Add Partner and Change Key Fields in EDIXRefUPC (09/18/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefUPCOld') > 0

BEGIN

    PRINT 'Drop Old Table EDIXrefUPCOld'

    PRINT 'If this command fails, ignore it or remove the table manually.'    

    DROP TABLE [dbo].[EDIXRefUPCOld]

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefUPCtoStockO') > 0

BEGIN

    PRINT 'Drop Old Table EDIXrefUPStoStockO'

    PRINT 'If this command fails, ignore it or remove the table manually.'    

    DROP TABLE [dbo].[EDIXRefUPCtoStockO]

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefUPC' AND COLUMN_NAME='ChangeDate') = 0

BEGIN

    ALTER TABLE EDIXRefUPC ADD

     ChangeDate               DATETIME            NULL,

     ChangeTime               CHAR(4)             NULL

    PRINT 'New Columns in EDIXRefUPC (12/19/2010)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefUPC' and COLUMN_NAME='UnitOfMeasure' and CHARACTER_MAXIMUM_LENGTH=3) = 1

BEGIN

  ALTER TABLE EDIXRefUPC DROP CONSTRAINT EDIXRefUPCKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefUPC' and COLUMN_NAME='UnitOfMeasure' and CHARACTER_MAXIMUM_LENGTH=3) = 1

BEGIN

  DROP INDEX EDIXRefUPC.EDIXRefUPCIdxCode

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefUPC' and COLUMN_NAME='UnitOfMeasure' and CHARACTER_MAXIMUM_LENGTH=3) = 1

BEGIN

    ALTER TABLE EDIXRefUPC ALTER COLUMN UnitOfMeasure CHAR(10) NOT NULL

     

 ALTER TABLE EDIXRefUPC

  ADD CONSTRAINT EDIXRefUPCKey PRIMARY KEY CLUSTERED

  (

         StockCode,

         Partner,

         Code,

         UnitOfMeasure

  )



CREATE UNIQUE INDEX EDIXRefUPCIdxCode ON EDIXRefUPC(

 Code,

 Partner,

 StockCode,

 UnitOfMeasure

 )

    PRINT 'Change columns EDIXRefUPC (06/10/2013)'

END

GO



PRINT 'Checking table EDIXRefVerifyCntry'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIXRefVerifyCntry') = 0

BEGIN

    CREATE TABLE EDIXRefVerifyCntry(

     Country                  CHAR(50)            NOT NULL,

     Code                     CHAR(10)            NULL,

     ProperCase               CHAR(50)            NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIXRefVerifyCntryKey PRIMARY KEY CLUSTERED

         (

          Country

         )

    )

    CREATE UNIQUE INDEX EDIXRefVerifyCntryIdxCode ON EDIXRefVerifyCntry(

     Code,

     Country

     )

    PRINT 'New table EDIXRefVerifyCntry (01/09/2017)'

END

GO



EXEC dbo.CadacusNewColumn '07/23/2019','C','EDIXRefVerifyCntry','State',1,0



PRINT 'Checking table EDIXRefVerifyState'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME = 'EDIXRefVerifyState') = 0

BEGIN

    CREATE TABLE EDIXRefVerifyState(

     Country                  CHAR(3)             NOT NULL,

     State                    CHAR(50)            NOT NULL,

     Code                     CHAR(10)            NULL,

     ProperCase               CHAR(50)            NULL,

     PostCodeFormat           CHAR(12)            NULL,

     PostcodeMin              DECIMAL(2,0)        NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIXRefVerifyStateKey PRIMARY KEY CLUSTERED

         (

          Country,

          State

         )

    )

    CREATE UNIQUE INDEX EDIXRefVerifyStateIdxCode ON EDIXRefVerifyState(

     Code,

     Country,

     State

     )

    PRINT 'New table EDIXRefVerifyState (01/09/2017)'

END

GO





PRINT 'Checking table EDIXRefWarehouse'

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefWarehouse' and COLUMN_NAME='Warehouse1' and CHARACTER_MAXIMUM_LENGTH=2) = 1

BEGIN

    ALTER TABLE EDIXRefWarehouse ALTER COLUMN Warehouse1  CHAR(10) 

    ALTER TABLE EDIXRefWarehouse ALTER COLUMN Warehouse2  CHAR(10) 

    ALTER TABLE EDIXRefWarehouse ALTER COLUMN Warehouse3  CHAR(10) 

    ALTER TABLE EDIXRefWarehouse ALTER COLUMN Warehouse4  CHAR(10) 

    ALTER TABLE EDIXRefWarehouse ALTER COLUMN Warehouse5  CHAR(10) 

    ALTER TABLE EDIXRefWarehouse ALTER COLUMN Warehouse6  CHAR(10) 

    ALTER TABLE EDIXRefWarehouse ALTER COLUMN Warehouse7  CHAR(10) 

    ALTER TABLE EDIXRefWarehouse ALTER COLUMN Warehouse8  CHAR(10) 

    ALTER TABLE EDIXRefWarehouse ALTER COLUMN Warehouse9  CHAR(10) 

    ALTER TABLE EDIXRefWarehouse ALTER COLUMN Warehouse10 CHAR(10) 



    PRINT 'Change columns EDIXRefWarehouse (06/10/2013)'

END

GO



PRINT 'Checking table EDIXRefWhseTrans'

GO



--  Add new 'EDIXRefWhseTrans' Table

IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES

    WHERE TABLE_NAME='EDIXRefWhseTrans') = 0

BEGIN

    CREATE TABLE EDIXRefWhseTrans(

     Warehouse1               CHAR(2)             NOT NULL,

     Warehouse2               CHAR(2)             NOT NULL,

     OneToTwo                 CHAR(1)             NULL,

     TwoToOne                 CHAR(1)             NULL,

     ExpIssuesOneToTwo        CHAR(1)             NULL,

     ExpIssuesTwoToOne        CHAR(1)             NULL,

     ImmedOneToTwo            CHAR(1)             NULL,

     ImmedTwoToOne            CHAR(1)             NULL,

     OutOneToTwo              CHAR(1)             NULL,

     OutTwoToOne              CHAR(1)             NULL,

     MsgOneToTwo              CHAR(30)            NULL,

     MsgTwoToOne              CHAR(30)            NULL,

     TimeStamp                timestamp           NULL,

     CONSTRAINT EDIXRefWhseTransKey PRIMARY KEY CLUSTERED

         (

          Warehouse1,

          Warehouse2

         )

    )

    PRINT 'New table EDIXRefWhseTrans (05/14/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefWhseTrans' AND COLUMN_NAME='ExpIssuesOneToTwo') = 0

BEGIN

    ALTER TABLE EDIXRefWhseTrans ADD 

     ExpIssuesOneToTwo        CHAR(1)             NULL,

     ExpIssuesTwoToOne        CHAR(1)             NULL

    PRINT 'Add new columns to EDIXRefWhseTrans  (05/15/2008)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefWhseTrans' AND COLUMN_NAME='ImmedOneToTwo') = 0

BEGIN

    ALTER TABLE EDIXRefWhseTrans ADD 

     ImmedOneToTwo            CHAR(1)             NULL,

     ImmedTwoToOne            CHAR(1)             NULL,

     OutOneToTwo              CHAR(1)             NULL,

     OutTwoToOne              CHAR(1)             NULL,

     MsgOneToTwo              CHAR(30)            NULL,

     MsgTwoToOne              CHAR(30)            NULL

    PRINT 'Add new columns to EDIXRefWhseTrans  (01/13/2010)'

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefWhseTrans' and COLUMN_NAME='Warehouse1' and CHARACTER_MAXIMUM_LENGTH=2) = 1

BEGIN

  ALTER TABLE EDIXRefWhseTrans DROP CONSTRAINT EDIXRefWhseTransKey

END

GO



IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

    WHERE TABLE_NAME='EDIXRefWhseTrans' and COLUMN_NAME='Warehouse1' and CHARACTER_MAXIMUM_LENGTH=2) = 1

BEGIN

    ALTER TABLE EDIXRefWhseTrans ALTER COLUMN Warehouse1  CHAR(10) NOT NULL

    ALTER TABLE EDIXRefWhseTrans ALTER COLUMN Warehouse2  CHAR(10) NOT NULL

    ALTER TABLE EDIXRefWhseTrans ALTER COLUMN MsgOneToTwo CHAR(50)

    ALTER TABLE EDIXRefWhseTrans ALTER COLUMN MsgTwoToOne CHAR(50)



 ALTER TABLE EDIXRefWhseTrans

   ADD CONSTRAINT EDIXRefWhseTransKey PRIMARY KEY CLUSTERED

   (

          Warehouse1,

          Warehouse2

   )



    PRINT 'Change columns EDIXRefWhseTrans (06/10/2013)'

END

GO



PRINT 'Checking removal of old DHL Tables'

GO



EXEC dbo.CadacusDropTable   'EDIDHLAccount', '06/10/2013'

EXEC dbo.CadacusDropTable   'EDIDHLDestMap', '06/10/2013'

EXEC dbo.CadacusDropTable   'EDIDHLHolidays', '06/10/2013'

EXEC dbo.CadacusDropTable   'EDIDHLHotCode', '06/10/2013'

EXEC dbo.CadacusDropTable   'EDIDHLOriginMap', '06/10/2013'

EXEC dbo.CadacusDropTable   'EDIDHLPostcode', '06/10/2013'

EXEC dbo.CadacusDropTable   'EDIDHLPriceBreak', '06/10/2013'

EXEC dbo.CadacusDropTable   'EDIDHLPricing', '06/10/2013'

EXEC dbo.CadacusDropTable   'EDIDHLPriceKey', '06/10/2013'

EXEC dbo.CadacusDropTable   'EDIDHLRedirect', '06/10/2013'

EXEC dbo.CadacusDropTable   'EDIDHLService', '06/10/2013'

EXEC dbo.CadacusDropTable   'EDIDHLServicePSC', '06/10/2013'

EXEC dbo.CadacusDropTable   'EDIDHLTransit', '06/10/2013'

EXEC dbo.CadacusDropTable   'EDIDHLValidVAS', '06/10/2013'

EXEC dbo.CadacusDropTable   'EDIDHLVasFee', '06/10/2013'

EXEC dbo.CadacusDropTable   'EDIDHLZone', '06/10/2013'

GO



--! End of SQL Updates



IF (SELECT COUNT(*) FROM EDIMasterDocument Where (Document='852' or Document='856' or Document='867') and ImportExport='I' and ProgramName='') > 0

BEGIN

  PRINT ' '

  PRINT '*** IMPORTANT NOTICE *** '

  PRINT 'There are one or more incoming 852, 856 or 867 documents configured in the EDI Solution.'

  PRINT 'Due to the addition of multiple methods of reporting/importing 852, 856 and 867 documents'

  PRINT 'it is necessary to open the correct document maintenance program for each 852, 856 and 867 documents'

  PRINT 'verify the configuration is correct and resave the configuration.'

  PRINT 'Failure to do this may result in the loss of the configuration information.'

  PRINT '*** IMPORTANT NOTICE *** '

  PRINT ' '

END

GO



IF (SELECT  COUNT(*) FROM #CadacusNewColumns where ColumnTable='EDIShipmentOrder' and ColumnName='Document') = 1

BEGIN

  PRINT ' '

  PRINT 'The EDIShipmentOrder table is being converted and EDIShipmentItem updated'

  PRINT 'This may take a while depending on the size of these tables'

  PRINT ' '

END

GO



IF (SELECT  COUNT(*) FROM #CadacusNewColumns where ColumnTable='EDIShipmentOrder' and ColumnName='Document') = 1

BEGIN

  EXEC dbo.CadacusDropPrimaryKey 'EDIShipmentOrder','Document',9

  EXEC dbo.CadacusDropIndex      'EDIShipmentOrder','Order','Document',9

  EXEC dbo.CadacusRenameColumn   '11/03/2021','EDIShipmentOrder','Dispatch','DispatchNote','Y'

END

GO



IF (SELECT  COUNT(*) FROM #CadacusNewColumns where ColumnTable='EDIShipmentOrder' and ColumnName='Document') = 1

BEGIN

  SET NOCOUNT ON



  Update EDIShipmentOrder Set Document=1

  

  DECLARE @Shipment     DECIMAL(9,0)

  DECLARE @LastShipment DECIMAL(9,0)

  DECLARE @Doc          DECIMAL(9,0)

  DECLARE @SalesOrder   VARCHAR(20)

  DECLARE @DispatchNote VARCHAR(20)



  DECLARE Shipments CURSOR FOR

    SELECT Shipment FROM EDIShipmentOrder Group by Shipment Having Count(*) > 1 Order by Shipment



  OPEN Shipments

  FETCH NEXT From Shipments INTO @Shipment

  WHILE @@FETCH_STATUS = 0

  BEGIN

    DECLARE SetDocs CURSOR FOR

      SELECT SalesOrder, DispatchNote FROM EDIShipmentOrder Where Shipment=@Shipment Order by SalesOrder, DispatchNote



    SET @Doc = 1

    OPEN SetDocs

    FETCH NEXT FROM SetDocs INTO @SalesOrder, @DispatchNote  -- Skip first as it is already set to 1

    FETCH NEXT FROM SetDocs INTO @SalesOrder, @DispatchNote

    WHILE @@FETCH_STATUS = 0

	  BEGIN

        SET @Doc = @Doc + 1

        PRINT 'Setting document number to '+CAST(@Doc AS varchar)+' for shipment '+CAST(@Shipment AS varchar)+' sales order '+@SalesOrder+' '+@DispatchNote

        EXEC ('Update EDIShipmentOrder Set Document='+@Doc+' WHERE Shipment='+@Shipment+' and SalesOrder='''+@SalesOrder+''' and DispatchNote='''+@DispatchNote+'''')   

        FETCH NEXT FROM SetDocs INTO @SalesOrder, @DispatchNote

      END

    CLOSE SetDocs

    DEALLOCATE SetDocs

    FETCH NEXT From Shipments INTO @Shipment

  END   

  

  CLOSE Shipments

  DEALLOCATE Shipments

  

/*  DECLARE SetDocs CURSOR FOR

    SELECT Shipment, SalesOrder, DispatchNote FROM EDIShipmentOrder order by Shipment, SalesOrder, DispatchNote

  

  SET @LastShipment = 0

  SET @Doc = 0

  

  OPEN SetDocs

  FETCH NEXT FROM SetDocs INTO @Shipment, @SalesOrder, @DispatchNote

  WHILE @@FETCH_STATUS = 0

  BEGIN

    IF @Shipment <> @LastShipment

      BEGIN

        SET @Doc = 1

        SET @LastShipment = @Shipment

      END

    ELSE

      BEGIN

        SET @Doc = @Doc + 1

      END

    --PRINT 'Setting document number to '+CAST(@Doc AS varchar)+' for shipment '+CAST(@Shipment AS varchar)+' sales order '+@SalesOrder+' '+@DispatchNote

    EXEC ('Update EDIShipmentOrder Set Document='+@Doc+' WHERE Shipment='+@Shipment+' and SalesOrder='''+@SalesOrder+''' and DispatchNote='''+@DispatchNote+'''')   

    FETCH NEXT FROM SetDocs INTO @Shipment, @SalesOrder, @DispatchNote

  END   

  

  CLOSE SetDocs

  DEALLOCATE SetDocs

*/  

  Print ''

  PRINT 'Updating EDIShipmentItem table with document numbers'



  ALTER TABLE EDIShipmentOrder ALTER COLUMN Document Decimal(9,0) NOT NULL;



  EXEC ('Update EDIShipmentItem

			Set EDIShipmentItem.Document=

				(Select EDIShipmentOrder.Document from EDIShipmentOrder where

					EDIShipmentOrder.Shipment     = EDIShipmentItem.Shipment and

					EDIShipmentOrder.SalesOrder   = EDIShipmentItem.SalesOrder and

					EDIShipmentOrder.DispatchNote = EDIShipmentItem.DispatchNote )')



  EXEC dbo.CadacusAddPrimaryKey 'EDIShipmentOrder','Shipment, Document'

  EXEC dbo.CadacusAddIndex      'EDIShipmentOrder', 'Order',    'SalesOrder, DispatchNote, Shipment'

  EXEC dbo.CadacusAddIndex      'EDIShipmentOrder', 'Dispatch', 'DispatchNote, SalesOrder, Shipment'

  EXEC dbo.CadacusAddIndex      'EDIShipmentOrder', 'Shipment', 'Shipment, SalesOrder, DispatchNote'

  Print ''

END

GO



IF (SELECT  COUNT(*) FROM #CadacusNewColumns where ColumnTable='EDIShipmentAdd' and ColumnName='Document') = 1

BEGIN

  PRINT 'Updating EDIShipmentAdd table with document numbers'

  EXEC dbo.CadacusDropPrimaryKey 'EDIShipmentAdd','X',1

  EXEC ('Update EDIShipmentAdd Set Document=0')  



  EXEC ('Update EDIShipmentAdd

			Set EDIShipmentAdd.Document=

				(Select EDIShipmentOrder.Document from EDIShipmentOrder where

					EDIShipmentOrder.Shipment     = EDIShipmentAdd.Shipment and

					EDIShipmentOrder.SalesOrder   = EDIShipmentAdd.SalesOrder) where EDIShipmentAdd.SalesOrder > '' ''')



  EXEC ('Update EDIShipmentAdd Set Document=0 Where Document IS NULL')  



  ALTER TABLE EDIShipmentAdd ALTER COLUMN Document Decimal(9,0) NOT NULL;



  EXEC dbo.CadacusAddPrimaryKey  'EDIShipmentAdd','Shipment, Document, Number'

  EXEC dbo.CadacusAddIndex       'EDIShipmentAdd', 'Order', 'Shipment, SalesOrder, Document, Number'

END

GO



IF (SELECT  COUNT(*) FROM #CadacusNewColumns where ColumnTable='EDILabelMaster' and ColumnName='Document') = 1

BEGIN

  PRINT 'Updating EDILabelMaster table with document numbers'

  

  EXEC ('Update EDILabelMaster

			Set EDILabelMaster.Document=

				(Select EDIShipmentOrder.Document from EDIShipmentOrder where

					EDIShipmentOrder.Shipment     = EDILabelMaster.Shipment and

					EDIShipmentOrder.SalesOrder   = EDILabelMaster.SalesOrder)')



  EXEC ('Update EDILabelMaster Set Document=0 Where Document IS NULL')  

END

GO



DROP FUNCTION dbo.CadacusIndexTest

DROP FUNCTION dbo.CadacusColumnTest



DROP PROCEDURE dbo.CadacusError

DROP PROCEDURE dbo.CadacusNewColumn

DROP PROCEDURE dbo.CadacusNewColumnNotNull

DROP PROCEDURE dbo.CadacusNewColumnNoDefault

DROP PROCEDURE dbo.CadacusNewColumnA

DROP PROCEDURE dbo.CadacusAlterColumn

DROP PROCEDURE dbo.CadacusDropPrimaryKey

DROP PROCEDURE dbo.CadacusAddPrimaryKey

DROP PROCEDURE dbo.CadacusDropIndex

DROP PROCEDURE dbo.CadacusAddIndex

DROP PROCEDURE dbo.CadacusRenameColumn

DROP PROCEDURE dbo.CadacusDropTable

GO



PRINT 'Checking default value for new columns'

GO



SET NOCOUNT ON

DECLARE @TABLE_NAME VARCHAR(100)

DECLARE @COLUMN_NAME VARCHAR(100)

DECLARE @COLUMN_TYPE VARCHAR(1)



DECLARE NewColumns CURSOR FOR

  SELECT ColumnType, ColumnTable, ColumnName FROM #CadacusNewColumns



OPEN NewColumns

FETCH NEXT FROM NewColumns INTO @COLUMN_TYPE, @TABLE_NAME, @COLUMN_NAME

WHILE @@FETCH_STATUS = 0

BEGIN

  PRINT 'Setting default value on new column : '+@TABLE_NAME+'..'+@COLUMN_NAME

  IF @COLUMN_TYPE = 'C'

    BEGIN

      EXEC ('UPDATE '+@TABLE_NAME+' SET '+@COLUMN_NAME+'='''' WHERE '+@COLUMN_NAME+' IS NULL')   

    END

/*  Leave dates as NULL

  IF @COLUMN_TYPE = 'D'

    BEGIN

      EXEC ('UPDATE '+@TABLE_NAME+' SET '+@COLUMN_NAME+'=Cast(''01/01/1900'' as datetime) WHERE '+@COLUMN_NAME+' IS NULL')   

    END  */

  IF @COLUMN_TYPE = 'N'

    BEGIN

      EXEC ('UPDATE '+@TABLE_NAME+' SET '+@COLUMN_NAME+'=0 WHERE '+@COLUMN_NAME+' IS NULL')   

    END

  FETCH NEXT FROM NewColumns INTO @COLUMN_TYPE, @TABLE_NAME, @COLUMN_NAME

END   

CLOSE NewColumns

DEALLOCATE NewColumns

GO



DROP Table #CadacusNewColumns

GO



PRINT ' '

PRINT 'Note :  Please scroll through the message report'

PRINT '        Any messages starting with ##### ERROR #####'

PRINT '        should be reported to your support organization for analysis'

PRINT ' '

PRINT 'SQL Script to update Cadacus, Inc. - Solutions for SYSPRO tables finished'

GO

