比如有一个表:
id name orderid
1 a 5
2 b 10
3 c 11
4 d 15
5 e 16
这样的表,点击按钮后那个orderid 变成 :5,10,15,20,25
就是每把原来的11变成了15,原来的15变成20,原来的16变成25,就是第一个数为5,以后的都要依次增加5
使用SQL的CASE函数。
DECLARE @ID int,@Orderid int;
DECLARE testCur CURSOR FOR SELECT id FROM Test
OPEN testCur
FETCH NEXT FROM testCur INTO @ID
WHILE(@@FETCH_status=0)
BEGIN
SELECT @Orderid=orderid FROM Test WHERE id=@ID;
FETCH NEXT FROM testCur INTO @ID
UPDATE Test SET orderid=@Orderid+5 WHERE id=@ID;
END
UPDATE Test SET orderid=orderid-5 WHERE id=@ID;
CLOSE testCur
DEALLOCATE testCur
随机数!!!