-----------------------------------------------------------------------------
-- ADVANTAGE 2004.5.0.0
-- DB OBJECT CHANGES
-- 21/04/2011
------------------------------------------------------------------------------



-------------------------------------------------------------------------------
-- INSERT DEFAULT VALUES for NEWLY CREATED COLUMN in 0.sql !!! Cannot do it there !!!
-------------------------------------------------------------------------------

--1. Modify AO_Suppliers table as follows
    IF EXISTS
        (
            SELECT * FROM SysObjects O
                INNER JOIN SysColumns C
                    ON O.ID = C.ID
            WHERE ObjectProperty(O.ID,'IsUserTable') = 1 AND
                  O.Name='AW_Company_Banks' AND
                  C.Name='Overdraft_Limit'
        ) 
        BEGIN
            UPDATE AW_Company_Banks
            SET Overdraft_Limit = 0
        END

-------------------------------------------------------



-------------------------------------------------------------------------------
-- NEW TABLES
-------------------------------------------------------------------------------

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AC_Periodic_Billing_Header]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[AC_Periodic_Billing_Header]
GO

CREATE TABLE [dbo].[AC_Periodic_Billing_Header] (
	[AC_Periodic_Billing_Header_ID] [int] IDENTITY (1, 1) NOT NULL ,
	[Posting_Type] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[Date_Posted] [datetime] NOT NULL ,
	[Slu_AW_Months_ID] [tinyint] NOT NULL ,
	[Slu_AW_Years_ID] [smallint] NOT NULL ,
	[Import_Filename] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[Date_Captured] [datetime] NULL ,
	[User_ID] [int] NULL ,
	[AW_User_Companies_ID] [int] NULL ,
	[Touched] [timestamp] NULL ,
	[Slu_AW_Active_ID] [tinyint] NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[AC_Periodic_Billing_Header] WITH NOCHECK ADD 
	CONSTRAINT [PK_AC_Periodic_Billing_Header] PRIMARY KEY  CLUSTERED 
	(
		[AC_Periodic_Billing_Header_ID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

setuser
GO

EXEC sp_bindefault N'[dbo].[df_User_Companies]', N'[AC_Periodic_Billing_Header].[AW_User_Companies_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_Date_Captured]', N'[AC_Periodic_Billing_Header].[Date_Captured]'
GO

EXEC sp_bindefault N'[dbo].[df_Date_Captured]', N'[AC_Periodic_Billing_Header].[Date_Posted]'
GO

EXEC sp_bindefault N'[dbo].[df_Nullstring]', N'[AC_Periodic_Billing_Header].[Import_Filename]'
GO

EXEC sp_bindefault N'[dbo].[df_Nullstring]', N'[AC_Periodic_Billing_Header].[Posting_Type]'
GO

EXEC sp_bindefault N'[dbo].[df_Active]', N'[AC_Periodic_Billing_Header].[Slu_AW_Active_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_Current_Month]', N'[AC_Periodic_Billing_Header].[Slu_AW_Months_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_Current_Year]', N'[AC_Periodic_Billing_Header].[Slu_AW_Years_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_User_ID]', N'[AC_Periodic_Billing_Header].[User_ID]'
GO

setuser
GO


-----------------------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AC_Periodic_Billing_Detail]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[AC_Periodic_Billing_Detail]
GO

CREATE TABLE [dbo].[AC_Periodic_Billing_Detail] (
	[AC_Periodic_Billing_Detail_ID] [int] IDENTITY (1, 1) NOT NULL ,
	[AC_Periodic_Billing_Header_ID] [int] NOT NULL ,
	[Post] [bit] NOT NULL ,
	[Transaction_Date] [datetime] NOT NULL ,
	[Ref_No] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[AC_Customers_ID] [int] NOT NULL ,
	[Sys_AW_Transaction_Types_ID] [tinyint] NOT NULL ,
	[Sys_AW_Tax_Methods_ID] [tinyint] NOT NULL ,
	[Amount] [money] NOT NULL ,
	[Tax_Amount] [money] NOT NULL ,
	[Net_Amount] [money] NOT NULL ,
	[AB_Accounts_ID] [int] NOT NULL ,
	[Comment] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[Notes] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[Email] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[Date_Captured] [datetime] NULL ,
	[User_ID] [int] NULL ,
	[AW_User_Companies_ID] [int] NULL ,
	[Touched] [timestamp] NULL ,
	[Slu_AW_Active_ID] [tinyint] NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[AC_Periodic_Billing_Detail] WITH NOCHECK ADD 
	CONSTRAINT [PK_AC_Periodic_Billing_Detail] PRIMARY KEY  CLUSTERED 
	(
		[AC_Periodic_Billing_Detail_ID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

setuser
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_One]', N'[AC_Periodic_Billing_Detail].[AB_Accounts_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_One]', N'[AC_Periodic_Billing_Detail].[AC_Customers_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AC_Periodic_Billing_Detail].[Amount]'
GO

EXEC sp_bindefault N'[dbo].[df_User_Companies]', N'[AC_Periodic_Billing_Detail].[AW_User_Companies_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_Nullstring]', N'[AC_Periodic_Billing_Detail].[Comment]'
GO

EXEC sp_bindefault N'[dbo].[df_Date_Captured]', N'[AC_Periodic_Billing_Detail].[Date_Captured]'
GO

EXEC sp_bindefault N'[dbo].[df_Nullstring]', N'[AC_Periodic_Billing_Detail].[Email]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AC_Periodic_Billing_Detail].[Net_Amount]'
GO

EXEC sp_bindefault N'[dbo].[df_Nullstring]', N'[AC_Periodic_Billing_Detail].[Notes]'
GO

EXEC sp_bindefault N'[dbo].[df_Nullstring]', N'[AC_Periodic_Billing_Detail].[Ref_No]'
GO

EXEC sp_bindefault N'[dbo].[df_Active]', N'[AC_Periodic_Billing_Detail].[Slu_AW_Active_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Three]', N'[AC_Periodic_Billing_Detail].[Sys_AW_Tax_Methods_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_One]', N'[AC_Periodic_Billing_Detail].[Sys_AW_Transaction_Types_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AC_Periodic_Billing_Detail].[Tax_Amount]'
GO

EXEC sp_bindefault N'[dbo].[df_Date_Captured]', N'[AC_Periodic_Billing_Detail].[Transaction_Date]'
GO

EXEC sp_bindefault N'[dbo].[df_User_ID]', N'[AC_Periodic_Billing_Detail].[User_ID]'
GO

setuser
GO


-----------------------------------------------

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AC_Periodic_Billing_Detail_Splits]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[AC_Periodic_Billing_Detail_Splits]
GO

CREATE TABLE [dbo].[AC_Periodic_Billing_Detail_Splits] (
	[AC_Periodic_Billing_Detail_Splits_ID] [int] IDENTITY (1, 1) NOT NULL ,
	[AC_Periodic_Billing_Header_ID] [int] NOT NULL ,
	[AC_Periodic_Billing_Detail_ID] [int] NOT NULL ,
	[AP_Products_ID] [int] NOT NULL ,
	[Quantity] [decimal](9, 3) NULL ,
	[Unit_Price] [money] NULL ,
	[Sys_AW_Tax_Methods_ID] [tinyint] NOT NULL ,
	[Amount] [money] NOT NULL ,
	[Tax_Amount] [money] NOT NULL ,
	[Net_Amount] [money] NOT NULL ,
	[Date_Captured] [datetime] NULL ,
	[User_ID] [int] NULL ,
	[AW_User_Companies_ID] [int] NULL ,
	[Touched] [timestamp] NULL ,
	[Slu_AW_Active_ID] [tinyint] NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[AC_Periodic_Billing_Detail_Splits] WITH NOCHECK ADD 
	CONSTRAINT [PK_AC_Periodic_Billing_Detail_Splits] PRIMARY KEY  CLUSTERED 
	(
		[AC_Periodic_Billing_Detail_Splits_ID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

setuser
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AC_Periodic_Billing_Detail_Splits].[Amount]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_One]', N'[AC_Periodic_Billing_Detail_Splits].[AP_Products_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_User_Companies]', N'[AC_Periodic_Billing_Detail_Splits].[AW_User_Companies_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_Date_Captured]', N'[AC_Periodic_Billing_Detail_Splits].[Date_Captured]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AC_Periodic_Billing_Detail_Splits].[Net_Amount]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_One]', N'[AC_Periodic_Billing_Detail_Splits].[Quantity]'
GO

EXEC sp_bindefault N'[dbo].[df_Active]', N'[AC_Periodic_Billing_Detail_Splits].[Slu_AW_Active_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Three]', N'[AC_Periodic_Billing_Detail_Splits].[Sys_AW_Tax_Methods_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AC_Periodic_Billing_Detail_Splits].[Tax_Amount]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AC_Periodic_Billing_Detail_Splits].[Unit_Price]'
GO

EXEC sp_bindefault N'[dbo].[df_User_ID]', N'[AC_Periodic_Billing_Detail_Splits].[User_ID]'
GO

setuser
GO

-----------------------------------------------

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AB_Cash_Inflow_Projections]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[AB_Cash_Inflow_Projections]
GO

CREATE TABLE [dbo].[AB_Cash_Inflow_Projections] (
	[AB_Cash_Inflow_Projections_ID] [int] IDENTITY (1, 1) NOT NULL ,
	[AW_Company_Banks_ID] [int] NULL ,
	[Post] [bit] NULL ,
	[Inflow_Date] [datetime] NULL ,
	[Description] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[Sys_AW_Tax_Methods_ID] [tinyint] NULL ,
	[Amount] [money] NULL ,
	[Tax_Amount] [money] NULL ,
	[Net_Amount] [money] NULL ,
	[Date_Captured] [datetime] NULL ,
	[User_ID] [int] NULL ,
	[AW_User_Companies_ID] [int] NULL ,
	[Touched] [timestamp] NULL ,
	[Slu_AW_Active_ID] [tinyint] NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[AB_Cash_Inflow_Projections] WITH NOCHECK ADD 
	CONSTRAINT [PK_AB_Cash_Inflow_Projections] PRIMARY KEY  CLUSTERED 
	(
		[AB_Cash_Inflow_Projections_ID]
	)  ON [PRIMARY] 
GO

setuser
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AB_Cash_Inflow_Projections].[Amount]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_One]', N'[AB_Cash_Inflow_Projections].[AW_Company_Banks_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_User_Companies]', N'[AB_Cash_Inflow_Projections].[AW_User_Companies_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_Date_Captured]', N'[AB_Cash_Inflow_Projections].[Inflow_Date]'
GO

EXEC sp_bindefault N'[dbo].[df_Date_Captured]', N'[AB_Cash_Inflow_Projections].[Date_Captured]'
GO

EXEC sp_bindefault N'[dbo].[df_Nullstring]', N'[AB_Cash_Inflow_Projections].[Description]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AB_Cash_Inflow_Projections].[Net_Amount]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AB_Cash_Inflow_Projections].[Tax_Amount]'
GO

EXEC sp_bindefault N'[dbo].[df_User_ID]', N'[AB_Cash_Inflow_Projections].[User_ID]'
GO

setuser
GO

-----------------------------------------------

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AB_Cash_Outflow_Projections]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[AB_Cash_Outflow_Projections]
GO

CREATE TABLE [dbo].[AB_Cash_Outflow_Projections] (
	[AB_Cash_Outflow_Projections_ID] [int] IDENTITY (1, 1) NOT NULL ,
	[AW_Company_Banks_ID] [int] NULL ,
	[Post] [bit] NULL ,
	[Outflow_Date] [datetime] NULL ,
	[Description] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[Sys_AW_Tax_Methods_ID] [tinyint] NULL ,
	[Amount] [money] NULL ,
	[Tax_Amount] [money] NULL ,
	[Net_Amount] [money] NULL ,
	[Date_Captured] [datetime] NULL ,
	[User_ID] [int] NULL ,
	[AW_User_Companies_ID] [int] NULL ,
	[Touched] [timestamp] NULL ,
	[Slu_AW_Active_ID] [tinyint] NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[AB_Cash_Outflow_Projections] WITH NOCHECK ADD 
	CONSTRAINT [PK_AB_Cash_Outflow_Projections] PRIMARY KEY  CLUSTERED 
	(
		[AB_Cash_Outflow_Projections_ID]
	)  ON [PRIMARY] 
GO

setuser
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AB_Cash_Outflow_Projections].[Amount]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_One]', N'[AB_Cash_Outflow_Projections].[AW_Company_Banks_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_User_Companies]', N'[AB_Cash_Outflow_Projections].[AW_User_Companies_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_Date_Captured]', N'[AB_Cash_Outflow_Projections].[Outflow_Date]'
GO

EXEC sp_bindefault N'[dbo].[df_Date_Captured]', N'[AB_Cash_Outflow_Projections].[Date_Captured]'
GO

EXEC sp_bindefault N'[dbo].[df_Nullstring]', N'[AB_Cash_Outflow_Projections].[Description]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AB_Cash_Outflow_Projections].[Net_Amount]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AB_Cash_Outflow_Projections].[Tax_Amount]'
GO

EXEC sp_bindefault N'[dbo].[df_User_ID]', N'[AB_Cash_Outflow_Projections].[User_ID]'
GO

setuser
GO

-----------------------------------------------

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AB_Cash_Flow_Forecast_Temp]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[AB_Cash_Flow_Forecast_Temp]
GO

CREATE TABLE [dbo].[AB_Cash_Flow_Forecast_Temp] (
	[AB_Cash_Flow_Forecast_Temp_ID] [int] IDENTITY (1, 1) NOT NULL ,
	[Description] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[N1] [tinyint] NULL ,
	[M1] [bigint] NULL ,
	[M2] [bigint] NULL ,
	[M3] [bigint] NULL ,
	[M4] [bigint] NULL ,
	[M5] [bigint] NULL ,
	[M6] [bigint] NULL ,
	[T1] [bigint] NULL ,
	[RowTypeID] [tinyint] NULL ,
	[StartDate] [datetime] NULL ,
	[AW_User_Companies_ID] [int] NULL 
) ON [PRIMARY]
GO

 CREATE  CLUSTERED  INDEX [CI_AB_Cash_Flow_Forecast_Temp] ON [dbo].[AB_Cash_Flow_Forecast_Temp]([N1], [RowTypeID], [Description]) ON [PRIMARY]
GO

 CREATE  UNIQUE  INDEX [IX_AB_Cash_Flow_Forecast_Temp] ON [dbo].[AB_Cash_Flow_Forecast_Temp]([AB_Cash_Flow_Forecast_Temp_ID]) ON [PRIMARY]
GO

setuser
GO

EXEC sp_bindefault N'[dbo].[df_User_Companies]', N'[AB_Cash_Flow_Forecast_Temp].[AW_User_Companies_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_Nullstring]', N'[AB_Cash_Flow_Forecast_Temp].[Description]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AB_Cash_Flow_Forecast_Temp].[M1]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AB_Cash_Flow_Forecast_Temp].[M2]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AB_Cash_Flow_Forecast_Temp].[M3]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AB_Cash_Flow_Forecast_Temp].[M4]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AB_Cash_Flow_Forecast_Temp].[M5]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AB_Cash_Flow_Forecast_Temp].[M6]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AB_Cash_Flow_Forecast_Temp].[N1]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AB_Cash_Flow_Forecast_Temp].[RowTypeID]'
GO

EXEC sp_bindefault N'[dbo].[df_Todays_Date]', N'[AB_Cash_Flow_Forecast_Temp].[StartDate]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AB_Cash_Flow_Forecast_Temp].[T1]'
GO

setuser
GO



-----------------------------------------------






-------------------------------------------------------
-- POPULATE DATA
-------------------------------------------------------


-------------------------------------------------------------------------------
-- NEW REPORTS
-------------------------------------------------------------------------------

    IF NOT EXISTS
        (
            SELECT Sys_AW_Reports_ID
            FROM Sys_AW_Reports
            WHERE Report_No = '117' AND
                  Method_Name = 'Show_ExportSales'
        ) 
        BEGIN
            INSERT Sys_AW_Reports
                (
                    Sys_AW_Modules_ID,
                    Type_ID,
                    Location,
                    Report_No,
                    Report_Name,
                    Description,
                    Object_DLL,
                    Class_Name,
                    Method_Name
                )
            VALUES
                (
                    1,
                    0,
                    'Sales Reports',
                    '117',
                    'Export Sales',
                    'Export Sales',
                    'SpSSalesReports',
                    'CInterface',
                    'Show_ExportSales'
                )
        END

----------------------------------------------

    IF NOT EXISTS
        (
            SELECT Sys_AW_Reports_ID
            FROM Sys_AW_Reports
            WHERE Report_No = '322' AND
                  Method_Name = 'Show_ProspectListing'
        ) 
        BEGIN
            INSERT Sys_AW_Reports
                (
                    Sys_AW_Modules_ID,
                    Type_ID,
                    Location,
                    Report_No,
                    Report_Name,
                    Description,
                    Object_DLL,
                    Class_Name,
                    Method_Name
                )
            VALUES
                (
                    3,
                    0,
                    'Customer Reports',
                    '322',
                    'Prospect Listing',
                    'Prospect Listing',
                    'SpSCustomerReports',
                    'CInterface',
                    'Show_ProspectListing'
                )
        END

----------------------------------------------

    IF NOT EXISTS
        (
            SELECT Sys_AW_Reports_ID
            FROM Sys_AW_Reports
            WHERE Report_No = '172' AND
                  Method_Name = 'Show_TillPayoutsAudit'
        ) 
        BEGIN
            INSERT Sys_AW_Reports
                (
                    Sys_AW_Modules_ID,
                    Type_ID,
                    Location,
                    Report_No,
                    Report_Name,
                    Description,
                    Object_DLL,
                    Class_Name,
                    Method_Name
                )
            VALUES
                (
                    1,
                    0,
                    'Sales Admin Reports',
                    '172',
                    'Till Payouts Audit Trail',
                    'Till Payouts Audit Trail',
                    'SpSSalesAdminReports',
                    'CInterface',
                    'Show_TillPayoutsAudit'
                )
        END

----------------------------------------------

-------------------------------------------------------------------------------
-- RETIRED REPORTS
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
-- DELETE REDUNDANT TABLES
-------------------------------------------------------------------------------



-------------------------------------------------------------------------------
--> DATA MODS
-------------------------------------------------------------------------------

UPDATE AB_Cash_Book_Transactions
SET Amount = 0
WHERE Amount IS NULL


UPDATE AB_Cash_Book_Transactions
SET Recon_Amount = 0
WHERE Recon_Amount IS NULL

----------------------------------------------

UPDATE Lup_AS_CBilling_Providers
SET Server_Name = '167.232.242.41'
WHERE Description = 'Four Fleet'

-------------------------------------------------------------------------------
--> NEW INDEXES
-------------------------------------------------------------------------------

IF EXISTS
    (
        SELECT name FROM sysindexes
        WHERE name = 'IX_SKU_Code'
    )
    BEGIN
        DROP INDEX AP_Products.IX_SKU_Code
    END
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AP_Products]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE INDEX [IX_SKU_Code] ON [dbo].[AP_Products] ([SKU_Code])
WITH FILLFACTOR = 90
ON [PRIMARY]
GO

----------------------------------------------

IF EXISTS
    (
        SELECT name FROM sysindexes
        WHERE name = 'IX_Supercession'
    )
    BEGIN
        DROP INDEX AP_Products.IX_Supercession
    END
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AP_Products]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE INDEX [IX_Supercession] ON [dbo].[AP_Products] ([Supercession])
WITH FILLFACTOR = 90
ON [PRIMARY]
GO

----------------------------------------------

IF EXISTS
    (
        SELECT name FROM sysindexes
        WHERE name = 'IX_Alternate_Code1'
    )
    BEGIN
        DROP INDEX AP_Products.IX_Alternate_Code1
    END
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AP_Products]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE INDEX [IX_Alternate_Code1] ON [dbo].[AP_Products] ([Alternate_Code1])
WITH FILLFACTOR = 90
ON [PRIMARY]
GO

----------------------------------------------

IF EXISTS
    (
        SELECT name FROM sysindexes
        WHERE name = 'IX_Alternate_Code2'
    )
    BEGIN
        DROP INDEX AP_Products.IX_Alternate_Code2
    END
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AP_Products]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE INDEX [IX_Alternate_Code2] ON [dbo].[AP_Products] ([Alternate_Code2])
WITH FILLFACTOR = 90
ON [PRIMARY]
GO

----------------------------------------------





----------------------------------------------



