
--Vendor Setting Type
	
	DECLARE @VendorSettingsTypes TABLE (RowId uniqueidentifier NOT NULL,[Name] [nvarchar](500) NOT NULL,SettingsType int NOT NULL);

	INSERT into @VendorSettingsTypes (RowId, [Name], SettingsType) VALUES ('d7e1cd43-c687-439f-a586-2491ee065bee', N'SendEmailForAMDEvents',1);
	INSERT into @VendorSettingsTypes (RowId, [Name], SettingsType) VALUES ('d7e1cd43-c687-439f-a586-2491ee065bff', N'SendEmailToAdminForAMDEvents',1);
	INSERT into @VendorSettingsTypes (RowId, [Name], SettingsType) VALUES ('d7e1cd43-c687-439f-a586-2491ee065bef', N'SendEmailToCaregiverForAMDEvents',1);

	MERGE INTO dbo.[VendorSettingsTypes] AS TARGET  
		USING @VendorSettingsTypes AS SOURCE  
		ON TARGET.RowId = SOURCE.RowId	
		WHEN MATCHED THEN    
			UPDATE SET	[Name] = SOURCE.[Name],
						[SettingsType] = SOURCE.[SettingsType]
		WHEN NOT MATCHED BY TARGET THEN   
			INSERT (RowId, [Name], SettingsType) VALUES (SOURCE.RowId, SOURCE.[Name], SOURCE.SettingsType)  
	OUTPUT $action, SOURCE.*;


--Adding Vendor Setting
insert into VendorSettings (VendorId,SettingTypeId,value)
	selecT vendorid,(select top 1 id from VendorSettingsTypes where rowid='d7e1cd43-c687-439f-a586-2491ee065bee'),'false'
	from VendorTbl v
	where 0 = (select count(1) from VendorSettings vs join VendorSettingsTypes t on t.Id=vs.SettingTypeId where VendorId=v.VendorId and t.rowid='d7e1cd43-c687-439f-a586-2491ee065bee' )
	union 
	selecT vendorid,(select top 1 id from VendorSettingsTypes where rowid='d7e1cd43-c687-439f-a586-2491ee065bff'),'false'
	from VendorTbl v
	where 0 = (select count(1) from VendorSettings vs join VendorSettingsTypes t on t.Id=vs.SettingTypeId where VendorId=v.VendorId and t.rowid='d7e1cd43-c687-439f-a586-2491ee065bff' )
	union 
	selecT vendorid,(select top 1 id from VendorSettingsTypes where rowid='d7e1cd43-c687-439f-a586-2491ee065bef'),'false'
	from VendorTbl v
	where 0 = (select count(1) from VendorSettings vs join VendorSettingsTypes t on t.Id=vs.SettingTypeId where VendorId=v.VendorId and t.rowid='d7e1cd43-c687-439f-a586-2491ee065bef' )
