IF NOT EXISTS( 
		SELECT	* FROM INFORMATION_SCHEMA.COLUMNS 
		WHERE	TABLE_NAME = 'pal_Report' 
				AND COLUMN_NAME = 'includeNotes')
BEGIN
    ALTER TABLE pal_Report 
    ADD includeNotes BIT NULL;
END

IF NOT EXISTS( 
		SELECT	* FROM INFORMATION_SCHEMA.COLUMNS 
		WHERE	TABLE_NAME = 'pal_Report' 
				AND COLUMN_NAME = 'notesLinkField')
BEGIN
    ALTER TABLE pal_Report 
    ADD notesLinkField VARCHAR(150) NULL;
END

IF NOT EXISTS( 
		SELECT	* FROM INFORMATION_SCHEMA.COLUMNS 
		WHERE	TABLE_NAME = 'pal_ReportNote' )
BEGIN
CREATE TABLE [dbo].[pal_ReportNote] (
    [recId]    INT           IDENTITY (1, 1) NOT NULL,
    [reportId] INT           NULL,
    [itemId]   VARCHAR (200) NULL,
    [note]     VARCHAR (MAX) NULL,
    CONSTRAINT [PK_pal_ReportNote] PRIMARY KEY CLUSTERED ([recId] ASC)
);
END

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

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

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

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

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

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

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


IF EXISTS (SELECT * FROM   sys.objects
           WHERE  object_id = OBJECT_ID(N'[dbo].[fn_STUD_1_GetPrepAttendancePrecentage]')
                  AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
	DROP FUNCTION [dbo].[fn_STUD_1_GetPrepAttendancePrecentage]

IF EXISTS (SELECT * FROM   sys.objects
           WHERE  object_id = OBJECT_ID(N'[dbo].[fn_STUD_1_GetPrepEnglishAveragePrecentage]')
                  AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
	DROP FUNCTION [dbo].[fn_STUD_1_GetPrepEnglishAveragePrecentage]

IF EXISTS (SELECT * FROM   sys.objects
           WHERE  object_id = OBJECT_ID(N'[dbo].[fn_STUD_1_GetPrepMathsAveragePrecentage]')
                  AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
	DROP FUNCTION [dbo].[fn_STUD_1_GetPrepMathsAveragePrecentage]

IF EXISTS (SELECT * FROM   sys.objects
           WHERE  object_id = OBJECT_ID(N'[dbo].[fn_STUD_1_GetPrepOtherSubjectAveragePrecentage]')
                  AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
	DROP FUNCTION [dbo].[fn_STUD_1_GetPrepOtherSubjectAveragePrecentage]

