
------------------------------------------------------------------------------
-- ADVANTAGE 2004.3.7
-- SCHEMA CHANGES SINCE ADVANTAGE 2004.3.6
-- 13 OCT 2008
------------------------------------------------------------------------------



------------------------------------------------------------------------------
-- COLUMN DROP statements commented to prevent loss of permanent data
------------------------------------------------------------------------------


--1. Modify AC_Customers table as follows
    IF NOT EXISTS
        (
            SELECT * FROM SysObjects O
                INNER JOIN SysColumns C
                    ON O.ID=C.ID
            WHERE ObjectProperty(O.ID,'IsUserTable') = 1 AND
                  O.Name='AC_Customers' AND
                  C.Name='AW_YesNo_CostPlus_Billing_ID'
        ) 
        BEGIN
            ALTER TABLE AC_Customers ADD AW_YesNo_CostPlus_Billing_ID tinyint NULL

            EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AC_Customers].[AW_YesNo_CostPlus_Billing_ID]'
        END


--2. Modify AC_Customers table as follows
    IF NOT EXISTS
        (
            SELECT * FROM SysObjects O
                INNER JOIN SysColumns C
                    ON O.ID=C.ID
            WHERE ObjectProperty(O.ID,'IsUserTable') = 1 AND
                  O.Name='AC_Customers' AND
                  C.Name='Lup_AC_Markup_Categories_ID'
        ) 
        BEGIN
            ALTER TABLE AC_Customers ADD Lup_AC_Markup_Categories_ID smallint NULL

            EXEC sp_bindefault N'[dbo].[df_Numeric_One]', N'[AC_Customers].[Lup_AC_Markup_Categories_ID]'
        END


--3. Modify AP_Products table as follows
    IF NOT EXISTS
        (
            SELECT * FROM SysObjects O
                INNER JOIN SysColumns C
                    ON O.ID=C.ID
            WHERE ObjectProperty(O.ID,'IsUserTable') = 1 AND
                  O.Name='AP_Products' AND
                  C.Name='Lup_AP_Markup_Groups_ID'
        ) 
        BEGIN
            ALTER TABLE AP_Products ADD Lup_AP_Markup_Groups_ID smallint NULL

            EXEC sp_bindefault N'[dbo].[df_Numeric_One]', N'[AP_Products].[Lup_AP_Markup_Groups_ID]'
        END


    IF NOT EXISTS
        (
            SELECT * FROM SysObjects O
                INNER JOIN SysColumns C
                    ON O.ID=C.ID
            WHERE ObjectProperty(O.ID,'IsUserTable') = 1 AND
                  O.Name='AP_Products' AND
                  C.Name='Slu_AW_YesNo_Cost_Plus_Item'
        ) 
        BEGIN
            ALTER TABLE AP_Products ADD Slu_AW_YesNo_Cost_Plus_Item tinyint NULL

            EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AP_Products].[Slu_AW_YesNo_Cost_Plus_Item]'
        END


--4. Modify AW_Users table as follows
    IF NOT EXISTS
        (
            SELECT * FROM SysObjects O
                INNER JOIN SysColumns C
                    ON O.ID=C.ID
            WHERE ObjectProperty(O.ID,'IsUserTable') = 1 AND
                  O.Name='AW_Users' AND
                  C.Name='IsDataExporter'
        ) 
        BEGIN
            ALTER TABLE AW_Users ADD IsDataExporter tinyint NULL

            EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AW_Users].[IsDataExporter]'
        END



--5. Modify AB_Accounts table as follows
    IF NOT EXISTS
        (
            SELECT * FROM SysObjects O
                INNER JOIN SysColumns C
                    ON O.ID=C.ID
            WHERE ObjectProperty(O.ID,'IsUserTable') = 1 AND
                  O.Name='AB_Accounts' AND
                  C.Name='Lup_AB_Account_Groups_ID'
        ) 
        BEGIN
            ALTER TABLE AB_Accounts ADD Lup_AB_Account_Groups_ID int NULL

            EXEC sp_bindefault N'[dbo].[df_Numeric_One]', N'[AB_Accounts].[Lup_AB_Account_Groups_ID]'
        END


--6. Modify AB_Accounts table as follows
    IF NOT EXISTS
        (
            SELECT * FROM SysObjects O
                INNER JOIN SysColumns C
                    ON O.ID=C.ID
            WHERE ObjectProperty(O.ID,'IsUserTable') = 1 AND
                  O.Name='AB_Accounts' AND
                  C.Name='Lup_AB_Account_Divisions_ID'
        ) 
        BEGIN
            ALTER TABLE AB_Accounts ADD Lup_AB_Account_Divisions_ID int NULL

            EXEC sp_bindefault N'[dbo].[df_Numeric_One]', N'[AB_Accounts].[Lup_AB_Account_Divisions_ID]'
        END

--------------------------------------------
--  END
--------------------------------------------