HoustonGuy
Programmer
I can't get the syntax correct for using a case statement within a Merge Statement.
I've tried many variations. I found an example online once, but can't find it now. All of the online samples don't show conditional statements with the Merge Statement.
Here's what I'm trying to do:
Thank you in advance!
I've tried many variations. I found an example online once, but can't find it now. All of the online samples don't show conditional statements with the Merge Statement.
Here's what I'm trying to do:
SQL:
MERGE dbo.Target AS T -- Target
USING dbo.Source AS S -- Source
ON T.ID = S.ID
WHEN MATCHED THEN
UPDATE SET
Case S.CountField
WHEN 1 THEN
T.Field1 = S.Field1
,T.Field2 = S.Field2
,T.Field3 = S.Field3
WHEN 2 THEN
T.Field1 = S.Field11
,T.Field2 = S.Field12
,T.Field3 = S.Field13
end
;
Thank you in advance!