如何同时将空值设置为多列中的特定值?

How to simultaneously set null values to specific value in many columns?

我要实现的目标是根据另一个 table 上的值更新值,问题是我必须加入多个列。看看吧:

update excel_attributes
inner join info_columns on 
(excel_attributes.source = info_columns.source) and 
(excel_attributes.r010_table = info_columns.tableName) and  
(excel_attributes.r010_comment = info_columns.comment) and 
(excel_attributes.r010_column = info_columns.columnName) and  
(excel_attributes.r010_type = info_columns.Datatype)  

set excel_attributes.source_id = info_columns.info_columns_id;

还有两倍的列。显然 left join 在很多情况下都无济于事 (2^numOfCol).

这就是为什么我想将该值设置为等于而不是 null 以便能够执行 inner join

这样做是可以的,但是很无聊:

update excel_attributes
set col = ""
where isnull(col );

有什么想法吗?

您需要执行这种奇怪的更新的情况是不正常的。但是可以使用 iif 函数。其他 DBMS 的类似物是 here.

所以解决方案写在下面:

update excel_attributes
inner join info_columns on
(iif(isnull(excel_attributes.source), "", excel_attributes.source) = iif(isnull(info_columns.source), "", info_columns.source)) and 
(iif(isnull(excel_attributes.r010_table), "", excel_attributes.r010_table) = iif(isnull(info_columns.tableName), "", info_columns.tableName)) and 
(iif(isnull(excel_attributes.r010_comment), "", excel_attributes.r010_comment) = iif(isnull(info_columns.comment), "", info_columns.comment)) and 
(iif(isnull(excel_attributes.r010_column), "", excel_attributes.r010_column) = iif(isnull(info_columns.columnName), "", info_columns.columnName)) and 
(iif(isnull(excel_attributes.r010_type), "", excel_attributes.r010_type) = iif(isnull(info_columns.Datatype), "", info_columns.Datatype)) 

set excel_attributes.source_id = info_columns.info_columns_id;