日期:2014-05-18  浏览次数:20550 次

更新难题求救!!
我需要对一个表里符合条件的某个字段进行赋值更新,按一个整数值递增。请问有哪位兄弟知道怎么实现啊?小弟感激不尽!

例:

表   T   有字段A   ,A初始为NULL。另有整数   I=100
要实现将T表所有A字段为   NULL的记录查出,然后将I   的值写到   A,I   每赋值一条后自加   2



------解决方案--------------------
declare @t table(A int)
insert @t
select 1 union all
select NULL union all
select NULL union all
select NULL union all
select 4

----更新
declare @i int
set @i = 100
update @t set A = @i,@i = @i + 2 where A is null

----查看
select * from @t

/*结果
1
102
104
106
4
*/