MERGE [dbo].[AgentMetricsDocuments] AS T
    USING (VALUES (@Id, @Data)) AS S([Id], [Data])
    ON T.[Id] = S.[Id]
    WHEN MATCHED THEN
UPDATE
    SET T.[Data] = S.[Data]
    WHEN NOT MATCHED THEN
INSERT
(
[Id],
[Data])
VALUES (S.[Id], S.[Data]);
