DECLARE myCURSOR INSENSITIVE CURSOR
FOR select id from Tb_Class_Client WHERE ClassID =  694 and ClassNumber = ''
DECLARE @id varchar(50), @num int

OPEN myCURSOR
FETCH NEXT FROM myCURSOR INTO @id

WHILE @@FETCH_STATUS = 0
BEGIN

declare @ClassNumber varchar(3)
select  @ClassNumber = '0'+ convert(varchar(2), MAX(ClassNumber) + 1) from Tb_Class_Client WHERE ClassID =  694

select @id

update Tb_Class_Client set ClassNumber = @ClassNumber
WHERE ID =  @id

FETCH NEXT FROM myCURSOR INTO @id
END
CLOSE myCURSOR
DEALLOCATE myCURSOR

posted on 2012-12-20 10:55  过往云烟  阅读(164)  评论(0编辑  收藏  举报