﻿CREATE PROCEDURE [dbo].[USP_StudyTemplate_AddOrUpdate]
	@client VARCHAR(100),
	@user VARCHAR(300),
	@templateName VARCHAR(300),
	@content TEXT
AS
	
	MERGE [StudyTemplate] as st
	USING (VALUES(@client,@user,@templateName,@content)) as s ([Client], [User], [TemplateName], [Content])
	ON st.[Client]=s.[Client] AND st.[User] = s.[User] AND st.[TemplateName] = s.[TemplateName]
	WHEN MATCHED
		THEN UPDATE SET [Content] = s.[Content]
	WHEN NOT MATCHED THEN 
		INSERT ([Client], [User], [TemplateName], [Content])
		VALUES(@client, @user, @templateName, @content) 
	;


RETURN 0