clear markdown feedback
clear markdown feedback
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 3798712 fiddles created (41866 in the last week).

declare @rsn table (ChangeReason varchar(20) not null primary key, IsActive varchar(5) not null, CreatedOn datetime not null); insert @rsn (ChangeReason, IsActive, CreatedOn) values ('Other', 'true', '20190801 13:01:01'); with cte as (select * from (values ('Other'), ('Scope'), ('Change')) as x(rsn)) select * from cte; begin tran; merge into @rsn as target using (values ('Other'), ('Scope'), ('Change')) as source(rsn) on target.ChangeReason = source.rsn when not matched by target then insert (ChangeReason, IsActive, CreatedOn) values (rsn, 'true', getdate()) ; select * from @rsn; rollback tran;
rsn
Other
Scope
Change
ChangeReason IsActive CreatedOn
Change true 18/09/2019 19:53:00
Other true 01/08/2019 13:01:01
Scope true 18/09/2019 19:53:00
 hidden batch(es)