加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql-server – 更新表sql server中的前1条记录[重复]

发布时间:2020-12-12 06:55:55 所属栏目:MsSql教程 来源:网络整理
导读:参见英文答案 How to update and order by using ms sql5个答案我的查询 UPDATE TOP (1) TX_Master_PCBA SET TIMESTAMP2 = '2013-12-12 15:40:31.593'WHERE SERIAL_NO IN ('0500030309') ORDER BY TIMESTAMP2 DESC 使用TX_Master_PCBA表中的serial_No列我有10
参见英文答案 > How to update and order by using ms sql5个答案我的查询
UPDATE TOP (1) TX_Master_PCBA  
SET TIMESTAMP2 = '2013-12-12 15:40:31.593'
WHERE SERIAL_NO IN ('0500030309') 
ORDER BY TIMESTAMP2 DESC

使用TX_Master_PCBA表中的serial_No列我有10条记录,但我想将最新的TIMESTAMP2更新为当前日期时间。

上面的查询抛出错误:

Incorrect syntax near the keyword ‘TOP’.

解决方法

WITH UpdateList_view AS (
  SELECT TOP 1  * from TX_Master_PCBA 
  WHERE SERIAL_NO IN ('0500030309') 
  ORDER BY TIMESTAMP2 DESC 
)

update UpdateList_view 
set TIMESTAMP2 = '2013-12-12 15:40:31.593'

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读