我的查询
UPDATE TOP (1) TX_Master_PCBA SET TIMESTAMP2 = '2013-12-12 15:40:31.593' WHERE SERIAL_NO IN ('0500030309') ORDER BY TIMESTAMP2 DESC
使用表中的serial_No
列TX_Master_PCBA
我有10条记录,但我想更新最新TIMESTAMP2
的当前日期时间.
上面的查询抛出错误:
关键字"TOP"附近的语法不正确.
小智.. 39
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'
Kapil.. 22
UPDATE TX_Master_PCBA SET TIMESTAMP2 = '2013-12-12 15:40:31.593', G_FIELD='0000' WHERE TIMESTAMP2 IN ( SELECT TOP 1 TIMESTAMP2 FROM TX_Master_PCBA WHERE SERIAL_NO='0500030309' ORDER BY TIMESTAMP2 DESC -- You need to decide what column you want to sort on )
panky sharma.. 19
Kapil的接受答案存在缺陷,如果有2条或多条记录具有相同的时间戳,则会更新多条记录,而不是真正的前1条查询.
;With cte as ( SELECT TOP(1) email_fk FROM abc WHERE id= 177 ORDER BY created DESC ) UPDATE cte SET email_fk = 10
Ref Remus Rusanu Ans: - SQL更新top1行查询