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

	INSERT into @VendorSettingsTypes (RowId, [Name], SettingsType) VALUES ('3289fefd-7f1b-460d-bf5f-ee3aa52fefe3', N'TelitApiConfiguration',2);

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

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

	--Get the settings DB Id
	declare @TelitApiConfigurationId int

	select @TelitApiConfigurationId = Id from VendorSettingsTypes where RowId='3289fefd-7f1b-460d-bf5f-ee3aa52fefe3'
	
	--Add to ALL vendors
	INSERT into @VendorSettings select VendorTbl.VendorId,@TelitApiConfigurationId,'{"authenticationApiUrl":"https://api-de.devicewise.com/rest/auth","updateApiUrl":"https://api-de.devicewise.com/rest/activatedeactivateapirole/cdp.connection.batch.update","thingKey":"activatedeactivateapirole","appId":"668e9e67ba2b573ae1bbd67c","appToken":"dmiVssKuRLi23N4z"}' 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 MATCHED THEN    
			UPDATE SET	[Value] = SOURCE.[Value],
						[UpdatedUtc] = GetUtcDate()
		WHEN NOT MATCHED BY TARGET THEN   
			INSERT (VendorId, SettingTypeId, [Value],CreatedUtc,UpdatedUtc) VALUES (SOURCE.VendorId, SOURCE.SettingTypeId, SOURCE.[Value],GetUtcDate(),GetUtcDate())  
	OUTPUT $action, SOURCE.*;

	 