我试图在SQL编程中变得更高效。 我想运行一个循环来重复更新命令的字段名称只能通过数字后缀更改。使用While循环进行SQL Server更新
例如,而不是每次更新写出x_1, y_1
,然后x_2, y_2
:
DECLARE @a INT
DECLARE @b VARCHAR
SET @a = 1
WHILE @a < 30
set @b = @a
BEGIN
UPDATE source set h = h + "x_"[email protected]
where "y_"[email protected] = 'Sold'
SET @a = @a + 1
END
让我知道如果我可以澄清。我正在使用SQL Server 2005.
感谢您的任何指导。
我想申请亚当斯的解决方案,需要了解什么是在N”正确用法如下:
exec sp_executesql update source_temp set pmt_90_day = pmt_90_day + convert(money,'trans_total_'[email protected]'')
where convert(datetime,'effective_date_'[email protected]) <= dateadd(day,90,ORSA_CHARGE_OFF_DATE)
and DRC_FLAG_'[email protected] = 'C'
亚当,如果你能协助我对我的修订的问候,我将不胜感激。 – homerjay 2009-04-16 15:08:09