sql局部游标
来源:互联网 发布:手机淘宝上怎么买东西 编辑:程序博客网 时间:2024/05/16 13:42
delare my_cursor cursor local for select * from table
fetch next from my_cursor into @test,@test2
//for example
ALTER procedure Test
as
declare my_cursor cursor local --scroll表示可随意移动游标指针(否则只能向前),dynamic表示可以读写游标(否则游标只读)
for
select workerid,count(1) tep from worker group by workerid
order by count(1)
open my_cursor-----全部大客户电话号码
declare @workerid sysname
declare @mycount int
declare @count int
declare @more int
declare @sql varchar(2000)
set @count=(select count(*) from powercustomer)/(select count(distinct workerid) from worker)
set @more=(select count(*) from powercustomer)%(select count(distinct workerid) from worker)
begin
truncate table temptable
insert into temptable(phonenum) select distinct phonenum from powercustomer where phonenum not in (select distinct phonenum from worker)
end
begin
fetch next from my_cursor into @workerid,@mycount
while(@@fetch_status=0)
begin
print @more
if @more>0
begin
set @sql='update temptable set workerid='+@workerid+' where phonenum in (select top '+Convert(varchar,(@count-@mycount)+1)+' phonenum from temptable where workerid is null)'
set @more=@more-1
end
else if @more=0
begin
set @sql='update temptable set workerid='+@workerid+' where phonenum in (select top '+Convert(varchar,@count-@mycount)+' phonenum from temptable where workerid is null)'
end
exec(@sql)
--commit
fetch next from my_cursor into @workerid,@mycount
end
close my_cursor
end
- sql局部游标
- SQL 游标
- sql游标
- sql游标
- SQL 游标
- sql游标
- SQL -游标
- sql游标
- SQl游标
- SQL 游标
- Sql--游标
- sql游标
- sql游标
- sql 游标
- sql游标
- sql游标
- SQL游标
- sql游标
- 人月神话:软件界面交互和易用性改进总结
- D programming language v0.162 by Digital Mars
- 权限如何控制页面控件显示的解决方案
- CC386 v3.16 by LADsoft
- 世界杯强奸了我们的生活!
- sql局部游标
- 不错的创意
- smart工作流管理系统的安装与配置方法
- Session技术详解
- 芦沟桥事变纪念日
- 送最好的兄弟
- 无趣的一天
- 自定义SiteMap提供程式之-:SqlSiteMapProvider2
- ubuntu 安装笔记