Skip to content
Advertisement

Merge Null Values in Merge Command

i must merge multible database tables in a node js windows service.
so i decided to write a method that creates a sql string for this.

here is my method:

this method and the created sql string works nice, expect in one case.
if the value in the source table column is NULL the target will not be updated.
here is a screenshot for that case (table 1 target, table 2 source): enter image description here

why isnt it be updating and how to solve it?

edit: here is generated sql string:

Advertisement

Answer

NULL is a special case in any RDBMS.

When you write below condition in WHEN MATCHED clause:

it is not considering NULL for comparison – any comparison with NULL results into NULL.

If you want to handle NULL in comparison, you can write below clause (assumming is_correspondence_address is VARCHAR/NVARCHAR datatype):

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement