if not exists (select column_name from INFORMATION_SCHEMA.columns where table_name = '{objectQualifier}tblNaDevEventsRecurringEventDate' and column_name = 'NumberOfSpacesAvailable')
 begin
   alter table {databaseOwner}[{objectQualifier}tblNaDevEventsRecurringEventDate] add NumberOfSpacesAvailable int null
 end
GO

if not exists (select column_name from INFORMATION_SCHEMA.columns where table_name = '{objectQualifier}tblNaDevEventCategories' and column_name = 'ExcludeFromSearchFilters')
 begin
   alter table {databaseOwner}[{objectQualifier}tblNaDevEventCategories] add ExcludeFromSearchFilters bit not null default 0
 end
GO

alter procedure {databaseOwner}{objectQualifier}usp_nadevEventsInsertUpdateCategory
(
 @categoryId int,
 @moduleId int,
 @categoryName nvarchar(255),
 @isActive bit,
 @eventFontColor nvarchar(50),
 @eventColor nvarchar(50),
 @parentId int,
 @dnnRoleId int,
 @ExcludeFromSearchFilters bit
)

as

set nocount on
  
 if exists(select null from {databaseOwner}[{objectQualifier}tblNaDevEventCategories] where categoryId = @categoryId)
	begin
		update {databaseOwner}[{objectQualifier}tblNaDevEventCategories] set moduleId = @moduleId,
																			 categoryName = @categoryName,
																			 isActive = @isActive,
																			 eventFontColor =@eventFontColor,
																			 eventColor =@eventColor,
																			 parentId = @parentId,
																			 dnnRoleId =@dnnRoleId,
																			 ExcludeFromSearchFilters = @ExcludeFromSearchFilters																	  										 
									 
																			where categoryId = @categoryId
																			return @@identity
			end 
else
	insert into {databaseOwner}[{objectQualifier}tblNaDevEventCategories] (moduleId,categoryName,isActive,eventFontColor,eventColor,parentId,dnnRoleId,ExcludeFromSearchFilters)

	values (@moduleId,@categoryName,@isActive,@eventFontColor,@eventColor,@parentId,@dnnRoleId,@ExcludeFromSearchFilters)
	
	SELECT SCOPE_IDENTITY()

GO

if not exists (select column_name from INFORMATION_SCHEMA.columns where table_name = '{objectQualifier}tblNaDevEventsLocation' and column_name = 'ExcludeFromSearchFilters')
 begin
   alter table {databaseOwner}[{objectQualifier}tblNaDevEventsLocation] add ExcludeFromSearchFilters bit not null default 0
 end
GO

alter procedure {databaseOwner}{objectQualifier}usp_nadev_Event_Location_Save_Location
(
 @locationId int,
 @moduleId int,
 @locationName nvarchar(max),
 @isArchived bit,
 @parentId int,
 @longitude decimal(18,9),
 @latitude decimal(18,9),
 @eventFontColor nvarchar(50),
 @eventColor nvarchar(50),
 @address1 nvarchar(255),
 @address2 nvarchar(255),
 @city nvarchar(255),
 @postcode nvarchar(255),
 @country nvarchar(255),
 @state nvarchar (255),
 @ExcludeFromSearchFilters bit
)

as

set nocount on
  
 if exists(select null from {databaseOwner}[{objectQualifier}tblNaDevEventsLocation] where locationId = @locationId)
	begin
		update {databaseOwner}[{objectQualifier}tblNaDevEventsLocation] set moduleId = @moduleId,
																			 locationName = @locationName,
																			 isArchived = @isArchived,
																			 parentId = @parentId,
																			 longitude = @longitude,
																			 latitude = @latitude,
																			 eventFontColor =@eventFontColor,
																			 eventColor =@eventColor,
																			 address1 = @address1,
																			 address2 = @address2,
																			 city = @city,
																			 postcode = @postcode,
																			 country = @country,
																			 state =@state,
																			 ExcludeFromSearchFilters = @ExcludeFromSearchFilters
																		  										 
																			where locationId = @locationId
																			return @@identity
			end 
else
	insert into {databaseOwner}[{objectQualifier}tblNaDevEventsLocation] (moduleId,locationName,isArchived,parentId,longitude,latitude,eventFontColor,eventColor,address1,address2,city,postcode,country,state,ExcludeFromSearchFilters)

	values (@moduleId,@locationName,@isArchived,@parentId,@longitude,@latitude,@eventFontColor,@eventColor,@address1,@address2,@city,@postcode,@country,@state,@ExcludeFromSearchFilters)
	
	SELECT SCOPE_IDENTITY()

GO