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

alter procedure {databaseOwner}{objectQualifier}usp_nadev_Event_Price_Tier_Save
(
 @priceId int,
 @eventId int,
 @TierName nvarchar(255),
 @costPerPlace money,
 @dnnRoleId int,
 @sortOrder int,
 @additionalAttendeeCost money,
 @QtyRequired int
)

as

set nocount on
  
 if exists(select null from {databaseOwner}[{objectQualifier}tblNaDevEventPriceTier] where priceId = @priceId)
	begin
		update {databaseOwner}[{objectQualifier}tblNaDevEventPriceTier] set eventId = @eventId,
																			TierName = @TierName,
																			costPerPlace = @costPerPlace,
																			dnnRoleId = @dnnRoleId,
																			sortOrder = @sortOrder,
																			additionalAttendeeCost = @additionalAttendeeCost,
																			QtyRequired = @QtyRequired
																																					  										 
																			where priceId = @priceId
																			return @@identity
			end 
else
	insert into {databaseOwner}[{objectQualifier}tblNaDevEventPriceTier] (eventId,TierName,costPerPlace,dnnRoleId,sortOrder,additionalAttendeeCost,QtyRequired)

	values (@eventId,@TierName,@costPerPlace,@dnnRoleId,@sortOrder,@additionalAttendeeCost,@QtyRequired)
	
	SELECT SCOPE_IDENTITY()

GO


IF EXISTS (SELECT * FROM sys.objects o WHERE o.object_id = object_id(N'[FK_{objectQualifier}tblNaDevEventSignUpQuestion_tblNaDevEvents]') AND OBJECTPROPERTY(o.object_id, N'IsForeignKey') = 1)
BEGIN
	alter table {databaseOwner}[{objectQualifier}tblNaDevEventSignUpQuestion] drop constraint  [FK_{objectQualifier}tblNaDevEventSignUpQuestion_tblNaDevEvents]
 end
go
