if not exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}tblNaDevEventsMyWishList]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
 begin

	CREATE TABLE {databaseOwner}[{objectQualifier}tblNaDevEventsMyWishList](
		[WishListItemId] [int] IDENTITY(1,1) NOT NULL,
		[EventId] [int] NOT NULL,
		[StartDate] [datetime] not null,
		[EndDate] [datetime] not null,
		[UsedId] [int] not null
	 CONSTRAINT [PK_{objectQualifier}tblNaDevEventsMyWishList] PRIMARY KEY CLUSTERED 
	(
		[WishListItemId] ASC
	)
	)
 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)
)

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
																		  										 
																			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)

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

GO