Update pal_Setup
SET vatRate = 14
Where vatRate Is Null


IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_GetSalesData]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_GetSalesData]
END



IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'saleQTEPrefix'
      AND Object_ID = Object_ID(N'pal_Setup'))
BEGIN
    ALTER TABLE pal_Setup
	ADD saleQTEPrefix VARCHAR(100)
END

IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'saleQTEStartNum'
      AND Object_ID = Object_ID(N'pal_Setup'))
BEGIN
    ALTER TABLE pal_Setup
	ADD saleQTEStartNum int
END

IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'saleINVPrefix'
      AND Object_ID = Object_ID(N'pal_Setup'))
BEGIN
    ALTER TABLE pal_Setup
	ADD saleINVPrefix VARCHAR(100)
END

IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'saleINVStartNum'
      AND Object_ID = Object_ID(N'pal_Setup'))
BEGIN
    ALTER TABLE pal_Setup
	ADD saleINVStartNum int
END

IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'saleRCTPrefix'
      AND Object_ID = Object_ID(N'pal_Setup'))
BEGIN
    ALTER TABLE pal_Setup
	ADD saleRCTPrefix VARCHAR(100)
END

IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'saleRCTStartNum'
      AND Object_ID = Object_ID(N'pal_Setup'))
BEGIN
    ALTER TABLE pal_Setup
	ADD saleRCTStartNum int
END

IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'saleCRNPrefix'
      AND Object_ID = Object_ID(N'pal_Setup'))
BEGIN
    ALTER TABLE pal_Setup
	ADD saleCRNPrefix VARCHAR(100)
END

IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'saleCRNStartNum'
      AND Object_ID = Object_ID(N'pal_Setup'))
BEGIN
    ALTER TABLE pal_Setup
	ADD saleCRNStartNum int
END


IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'notesInvoices'
      AND Object_ID = Object_ID(N'pal_Setup'))
BEGIN
    ALTER TABLE pal_Setup
	ADD notesInvoices VARCHAR(MAX)
END

IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'notesQuotes'
      AND Object_ID = Object_ID(N'pal_Setup'))
BEGIN
    ALTER TABLE pal_Setup
	ADD notesQuotes VARCHAR(MAX)
END



IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'notesReceipts'
      AND Object_ID = Object_ID(N'pal_Setup'))
BEGIN
    ALTER TABLE pal_Setup
	ADD notesReceipts VARCHAR(MAX)
END

IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'notesCreditNotes'
      AND Object_ID = Object_ID(N'pal_Setup'))
BEGIN
    ALTER TABLE pal_Setup
	ADD notesCreditNotes VARCHAR(MAX)
END

IF NOT EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N'[dbo].[pal_SalesExtraNote]')
 AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
 BEGIN
 
	CREATE TABLE [dbo].[pal_SalesExtraNote](
		[recId] [int] IDENTITY(1,1) NOT NULL,
		[type] [int] NULL,
		[number] [int] NULL,
		[note] [text] NULL,
		[dateSaved] [datetime] NULL,
	 CONSTRAINT [PK_pal_SalesExtraNote] PRIMARY KEY CLUSTERED 
	(
		[recId] ASC
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
	) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

END