DECLARE @ResourceLocalizedValues TABLE (
    [LanguageId]     INT            NOT NULL,
    [EntityType]     INT            NOT NULL,
    [ResourceKey]    NVARCHAR (200) NOT NULL,
    [LocalizedValue] NVARCHAR (MAX) NOT NULL,
    [Description]    NVARCHAR (200) NULL
)

INSERT @ResourceLocalizedValues([LanguageId], [EntityType], [ResourceKey], [LocalizedValue]) VALUES (1, 15, 'SMSBody',
N'Hello, Account {0} reported an out-of-range {1} measurement at {2:dd/MM/yyyy HH:mm}. Severity: {3}  To view the measurement, log in to CareView')

INSERT @ResourceLocalizedValues([LanguageId], [EntityType], [ResourceKey], [LocalizedValue]) VALUES (1, 15, 'MailBody',
N'<div>Hello,</div><div>Account {0} reported an out-of-range {1} measurement at {2:dd/MM/yyyy HH:mm}.</div><div>Severity: {3}</div><div>To view the measurement in CareView, <a href=''Put Cv URL''>press here</a>.</div><div>To stop receiving these emails, contact your CareView administrator.</div>')
INSERT @ResourceLocalizedValues([LanguageId], [EntityType], [ResourceKey], [LocalizedValue]) VALUES (1, 15, 'MailSubject',N'VitalOn out-of-range measurement')
INSERT @ResourceLocalizedValues([LanguageId], [EntityType], [ResourceKey], [LocalizedValue]) VALUES (1, 15, 'MailSender',N'')


MERGE INTO [dbo].[ResourceLocalizedValues] AS TARGET  
USING @ResourceLocalizedValues AS SOURCE  
ON TARGET.[LanguageId] = SOURCE.[LanguageId]
	AND TARGET.[EntityType] = SOURCE.[EntityType]
	AND TARGET.[ResourceKey] = SOURCE.[ResourceKey]
WHEN NOT MATCHED BY TARGET THEN
INSERT ([LanguageId], [EntityType], [ResourceKey], [LocalizedValue])
VALUES (SOURCE.[LanguageId], SOURCE.[EntityType], SOURCE.[ResourceKey], SOURCE.[LocalizedValue])
WHEN MATCHED THEN    
UPDATE SET	TARGET.[LocalizedValue] = SOURCE.[LocalizedValue]
OUTPUT $ACTION, SOURCE.*;
