格式化SQL Update语句

时间:2016-05-16 19:39:30

标签: sql sql-server

我有以下格式的100条更新声明:

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'

2 个答案:

答案 0 :(得分: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;

然后,您可以加载包含大量行的更新表,并运行一个更新语句。

答案 1 :(得分:0)

使用Notepadd++之类的文本编辑器或任何其他高级编辑器,并为"运行替换CR + LF。 " (空格)。

enter image description here

SSMS也支持。

enter image description here