【问题标题】:Update Fields based on another Fields value (date fields)根据另一个字段值(日期字段)更新字段
【发布时间】:2016-01-14 23:38:51
【问题描述】:

目标:根据在 B 列“值字段”中查找值来更新 C 列“新日期”。 C 列“新日期”将是 A 列“当前日期”中的日期

我过去使用过以下内容,但现在我被要求提供第三个参数。我已经搜索并在最后尝试了“YYYY-MM-DD”,但无法完全找到答案。

软件:我在服务器管理中使用 SQL(2012)

UPDATE TBLTABLE
SET  NewDate= (CurrentDate + DATEADD(DAY,730)) 
WHERE VALUEFIELD = 'XYZ'

注意:使用我知道但我不“知道”每个“当前日期”字段的值的已知值进行更新,这也确保我不必运行不同的日期。

看过: Update Field based on another table's Field values

Update a column based on a field from another table

SQL UPDATE SET one column to be equal to a value in a related table referenced by a different column?

【问题讨论】:

    标签: sql-server


    【解决方案1】:

    这实际上取决于 CurrentDate 中的内容。我猜它是一个日期时间。

       UPDATE TBLTABLE
        SET  NewDate=  DATEADD(DAY,730,CurrentDate )
        WHERE VALUEFIELD = 'XYZ'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多