【问题标题】:Coping value of one column entry to another of same record ,If the value is null将一列条目的值复制到同一记录的另一列,如果该值为空
【发布时间】:2016-06-08 07:45:02
【问题描述】:

我的表中有两列。代码和 DocEntery 。如果 DocEntry 的值为“NULL”,我希望它更改为相应“代码”值的值。有很多行,所以你能告诉我任何可用于更新完整表的查询吗?我正在使用 SQL 服务器。

【问题讨论】:

  • Update Table set DocEntry = Code Where DocEntry IS NULL 如果 'NULL' 表示 varchar 包含 NULL 那么你当然需要更改 where 子句

标签: sql-server sql-server-2008 stored-procedures


【解决方案1】:

无需更新整个表或使用任何类型的CASE EXPRESSIONIF,只需过滤那些将NULL 的值,并更新所有这些值:

UPDATE YourTable t
SET t.DocEntry = t.Code
WHERE t.DocEntry is null

【讨论】:

    【解决方案2】:

    试试这个查询:

    Update table1 set DocEntry = (Case when DocEntry is NULL then Code Else DocEntry end)
    

    【讨论】:

      猜你喜欢
      • 2017-01-22
      • 1970-01-01
      • 2020-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-28
      • 1970-01-01
      相关资源
      最近更新 更多