
--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 ('E17A9042-1DE2-43E6-B980-03812284EF4D', N'IsSCAIPCallerIdInUse',1);
	INSERT into @VendorSettingsTypes (RowId, [Name], SettingsType) VALUES ('5386BA60-B623-412D-94DE-BA125053825A', N'IsSCAIPCallerIdLocal',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='E17A9042-1DE2-43E6-B980-03812284EF4D'),'true'
	--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='E17A9042-1DE2-43E6-B980-03812284EF4D' )
	--union 
	selecT vendorid,(select top 1 id from VendorSettingsTypes where rowid='5386BA60-B623-412D-94DE-BA125053825A'),'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='5386BA60-B623-412D-94DE-BA125053825A' )

