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

alter procedure {databaseOwner}{objectQualifier}usp_NADevEventsSaveCoupon
(
 @couponId int,
 @couponCode nvarchar(255),
 @description ntext,
 @minimumSubtotal money,
 @discount money,
 @canusemultipletimes bit,
 @expiryDate datetime,
 @hasbeenused bit,
 @moduleId int,
 @customeremailaddress nvarchar(50),
 @startdate datetime,
 @coupontype nvarchar(50),
 @eventId int,
 @eventStartDate datetime,
 @eventEndDate datetime,
 @CustomerEmailDomains ntext
)

as

set nocount on
  
 if exists(select null from {databaseOwner}[{objectQualifier}tblNaDevEventCoupons] where couponid = @couponid)
	begin
		update {databaseOwner}[{objectQualifier}tblNaDevEventCoupons] set couponCode = @couponcode,	 
																		  description = @description,
																		  minimumsubtotal = @minimumsubtotal,
																		  discount = @discount,
																		  canusemultipletimes = @canusemultipletimes,
																		  expirydate = @expirydate,
																		  hasbeenused = @hasbeenused,
																		  moduleId = @moduleId,
																		  customeremailaddress = @customeremailaddress,
																		  startdate = @startdate,
																		  coupontype = @coupontype,
																		  EventId = @eventId,
																		  EventStartDate = @eventStartDate,
																		  EventEndDate = @eventEndDate,
																		  CustomerEmailDomains = @CustomerEmailDomains						 
									 
																	      where couponid = @couponid
																	      return @@identity
			end 
else
	insert into {databaseOwner}[{objectQualifier}tblNaDevEventCoupons] (couponcode,description,minimumsubtotal,discount,canusemultipletimes,expirydate,hasbeenused,moduleid,customeremailaddress,startdate,coupontype,EventId,EventStartDate,EventEndDate,CustomerEmailDomains)

	values (@couponcode,@description,@minimumsubtotal,@discount,@canusemultipletimes,@expirydate,@hasbeenused,@moduleid,@customeremailaddress,@startdate,@coupontype,@eventId,@eventStartDate,@eventEndDate,@CustomerEmailDomains)
	
	SELECT SCOPE_IDENTITY()

GO