2016-05-16 162 views
0

我有以下格式的100個更新語句:格式化SQL Update語句

UPDATE Eli 
SET UserId = @ID, UpdateDate = @DATE, Indicator = 'C' 
WHERE Isdel = 'N' 
    AND TId = 56260563 
    AND Indicator = 'A' 
    AND ENumber = 21848963 
    AND CNumber = 111248400 
    AND PBDate = '2013-10-01' 

我如何把上面的更新語句的單行線,就像如下─

UPDATE Eli SET UserId = @ID, UpdateDate = @DATE, Indicator = 'C'WHERE Isdel = 'N'  AND TId = 56260563 AND Indicator = 'A' AND ENumber = 21848963 AND CNumber = 111248400  AND PBDate = '2013-10-01' 
+7

...它看起來像你已經把它放在一行,不是嗎?我錯過了什麼? – WillardSolutions

+0

爲什麼你不使用合併,所以你不必一直說和!你所要做的就是給出輸入值。這個問題在問什麼?你已經完成了這項工作,雖然 – JT4U

+0

我有100個這樣的更新說明。而不是手動,我想要一種方式來使用sql編輯器來格式化它們。 – user2961127

回答

0

使用文本編輯器,如Notepadd++或任何其他高級編輯器,以及runa替換」「(空格)的CR + LF。

enter image description here

通過SSMS也支持。

enter image description here

1

爲什麼格式化一堆的陳述?相反,使用數據加載表並使用JOIN。這裏是一個例子:

select @id as id, @date as updatedate, 'N' as isdel, 56260563 as tid, 
     'A' as indicator, 111248400 as CNumber, 
     cast('2013-10-01' as date) as PBDate 
into table_toupdate; 

UPDATE e 
    SET UserId = tu.id, UpdateDate = tu.updatedate, Indicator = 'C' 
    FROM Eli e JOIN 
     table_toupdate tu 
     ON e.isdel = tu.isdel and 
      e.tid = tu.tid and 
      e.enumber = tu.enumber and 
      e.cnumber = tu.cnumber and 
      e.pbdate = tu.pbdate; 

然後,您可以加載更新表與很多行,只是運行一個更新語句。 「