4,707 questions
Hi @Olaf Helper , My requirement is I have to insert some col1, col2. Out of this col2 is unique column. So already col2 having same value. So I want to update that value automatically while doing the insert.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi @everyone,
Please share your knowledge to do the on duplicate update in sql.
Hi @Olaf Helper , My requirement is I have to insert some col1, col2. Out of this col2 is unique column. So already col2 having same value. So I want to update that value automatically while doing the insert.
use the merge statement
merge MyTable t
using (select @col1, @col2) as s (col1, col2)
on t.col2 = s.col2
when matched then
update set col1 = s.col1
when not matched then
insert (col1, col2)
values (s.col1, s.col2)