【问题标题】:How to simultaneously set null values to specific value in many columns?如何同时将空值设置为多列中的特定值?
【发布时间】:2015-10-29 07:12:35
【问题描述】:

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

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 );

有什么想法吗?

【问题讨论】:

    标签: sql ms-access null sql-update ms-access-2010


    【解决方案1】:

    您需要执行这种奇怪的更新的情况是不正常的。但是可以使用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;
    

    【讨论】:

      猜你喜欢
      • 2018-09-25
      • 2017-10-24
      • 1970-01-01
      • 1970-01-01
      • 2015-07-10
      • 1970-01-01
      • 2016-08-01
      • 1970-01-01
      • 2021-04-10
      相关资源
      最近更新 更多