
--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 ('95E387E5-6EE1-4A2E-B5A3-5C1681CFC328', N'SendSMSForAMDEvents',1);
	INSERT into @VendorSettingsTypes (RowId, [Name], SettingsType) VALUES ('67AEA658-CC91-4A68-86BB-835A6DEC6AAA', N'SendSMSToAdminForAMDEvents',1);
	INSERT into @VendorSettingsTypes (RowId, [Name], SettingsType) VALUES ('148B16DC-6B2C-4ED2-979A-BDEFD51784BE', N'SendSMSToCaregiverForAMDEvents',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='95E387E5-6EE1-4A2E-B5A3-5C1681CFC328'),'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='95E387E5-6EE1-4A2E-B5A3-5C1681CFC328' )
	union 
	selecT vendorid,(select top 1 id from VendorSettingsTypes where rowid='67AEA658-CC91-4A68-86BB-835A6DEC6AAA'),'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='67AEA658-CC91-4A68-86BB-835A6DEC6AAA' )
	union 
	selecT vendorid,(select top 1 id from VendorSettingsTypes where rowid='148B16DC-6B2C-4ED2-979A-BDEFD51784BE'),'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='148B16DC-6B2C-4ED2-979A-BDEFD51784BE' )
