存储过程
- 一个简单存储过程例子
- CREATE PROCEDURE sp_cpsum_bylevel1 AS
- begin
- declare @code varchar(50)
- declare @num varchar(50)
- declare @command varchar(1000)
- declare cursor_tmp_1 cursor for select left(ypcode,2),count(left(ypcode,2)) from cpname where ylevel=3 group by left(ypcode,2)
- open cursor_tmp_1
- fetch next from cursor_tmp_1 into @code, @num
- while @@fetch_status = 0
- begin
- set @command = 'update cpname set shuliang ='''+ @num + ''' where ycode ='''+ @code +''' and ylevel=1'
- print @command
- EXEC (@command)
- fetch next from cursor_tmp_1 into @code, @num
- end
- close cursor_tmp_1
- deallocate cursor_tmp_1
- end
- GO
- 执行 exec sp_cpsum_bylevel1
posted on 2015-10-23 16:15 struggle_beiJing 阅读(168) 评论(0) 编辑 收藏 举报