0

i don't understand well how to use the merge statement, i need to translate the following into the equivalent merge statement. Is merge faster then update/insert?

ALTER PROCEDURE [dbo].[IOUUS] @a VARCHAR(50), @b VARCHAR(50), @c NVARCHAR(4000) AS BEGIN IF EXISTS ( SELECT c FROM T ) UPDATE T SET c = @c , d = GETUTCDATE() WHERE b = @b AND a = @a ELSE INSERT INTO T (a, b, c, d) VALUES (@a, @b, @c, GETUTCDATE()) END 

1 Answer 1

0

Try this one -

MERGE dbo.t t USING (SELECT @a, @b, @c, GETUTCDATE()) s (a, b, c, d) ON (t.b = s.b AND t.a = s.a) WHEN MATCHED THEN UPDATE SET c = s.c , d = s.d WHEN NOT MATCHED THEN INSERT (a, b, c, d) VALUES (s.a, s.b, s.c, s.d); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.