
-------------------------------------------------------------------------------
----------------------------Add new 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 ('fb945909-71b6-43a5-a648-09b4edba79c0', N'IgnoreIT0SinceLatestEventInMinutes',3);


	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.*;

--------------------------------------------------------------------------------
----------------------------Add new Setting's value by Type---------------------
--------------------------------------------------------------------------------

	DECLARE @VendorSettings TABLE (VendorId int NOT NULL, SettingTypeId int NOT NULL, Value nvarchar(1024) NULL);

	declare @settingTypeId int
	
	select @settingTypeId = Id from VendorSettingsTypes where RowId='fb945909-71b6-43a5-a648-09b4edba79c0'

	--Add to all vendors
	INSERT into @VendorSettings select VendorTbl.VendorId,@settingTypeId,'0' from VendorTbl order by VendorId

	MERGE INTO dbo.[VendorSettings] AS TARGET  
		USING @VendorSettings AS SOURCE  
		ON TARGET.VendorId = SOURCE.VendorId and TARGET.SettingTypeId = SOURCE.SettingTypeId	
		WHEN NOT MATCHED BY TARGET THEN   
			INSERT (VendorId, SettingTypeId, [Value],CreatedUtc,UpdatedUtc) VALUES (SOURCE.VendorId, SOURCE.SettingTypeId, SOURCE.[Value],GetUtcDate(),GetUtcDate())  
	OUTPUT $action, SOURCE.*;

