Consider the following:
merge into T t1
using (select ID,Col1 from T where ID = 123) t2
on 1 = 0
when not matched then insert (Col1) values (t2.Col1);
Cominig from a programming background, to me this translates to:
"Evaluate false
(i.e. 1 = 0), and when it is false
(i.e. all the time), insert."
Is it not possible to just omit the match condition?
Is it because of my select's where
condition that I'm confused here? Should this condition be moved to the on
?
NOTE:
Due to restrictions with output
, I cannot use insert
. I need to output the results of this merge into a temporary table for reasons outside of the scope of what I'm asking.