IF((SELECT	COUNT(1) FROM pal_SurfaceActionType WHERE actionType = 'Field Aggregation') = 0)
BEGIN
INSERT INTO pal_SurfaceActionType
SELECT	'Field Aggregation',1
END

IF((SELECT	COUNT(1) FROM pal_SurfaceAction WHERE actionType = 8 AND [action] = 'Average') = 0)
BEGIN
INSERT INTO pal_SurfaceAction
SELECT	8,'Average',1
END

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

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