Oracle到SQL Server查询

时间:2016-08-01 18:28:44

标签: sql-server oracle

我通常使用Oracle,这样的查询非常简单。我用脑子搜索了脑袋。基本上它是获取先前记录记录的最大标识符。

在Oracle中我会做这样的更新

UPDATE NOTES N1
SET MASTER_RECORD_NUMBER = 
(SELECT MAX(MASTER_RECORD_NUMBER)
 FROM NOTES N2
 WHERE N1.CUSTOMER_NO = N2.CUSTOMER_NO
 AND N2.MASTER_RECORD_NUMBER < N1.MASTER_RECORD_NUMBER
 AND N2.CODE IS NOT NULL)
WHERE N1.CODE IS NULL;

基本上记录号是顺序的,如果是连续的话,代码不存在。查询比这更长,涉及日期等,但这通常是我想要做的。

1 个答案:

答案 0 :(得分:0)

试试这个..

UPDATE  N1
SET MASTER_RECORD_NUMBER = 
(SELECT MAX(MASTER_RECORD_NUMBER)
 FROM NOTES N2
 WHERE N1.CUSTOMER_NO = N2.CUSTOMER_NO
 AND N2.MASTER_RECORD_NUMBER < N1.MASTER_RECORD_NUMBER
 AND N2.CODE IS NOT NULL)
 from notes n1
WHERE N1.CODE IS NULL;