2016-01-20 90 views
0

我想要使用至close_dateClose_time的順序更新表。使用SQL語句中的語句更新表

我的表是:

這樣

enter image description here

我試圖查詢:

WITH cte AS 
(
    SELECT 
     Terminal_Id, Close_date, Close_time, SlNo, 
     ROW_NUMBER() OVER (ORDER BY Close_date,Close_time) AS RN 
    FROM 
     tablename 
) 
UPDATE cte 
SET SlNo = RN 
+0

什麼'UPDATE CTE '??? – Rahul

+0

我正在嘗試使用cte @ Rahul – tbs

+0

基本上我想更新表名,其中Close_date和Close_time將按升序排列 – tbs

回答

0

我認爲這是可以薄如這樣的:

With cte As 
(
SELECT SlNo,ROW_NUMBER() OVER (ORDER BY Close_date,Close_time) AS RN 
FROM tablename 
) 
UPDATE cte SET SlNo=RN