首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

SQLSERVER游标的施用

2013-02-24 
SQLSERVER游标的使用declare @user_name varchar(100)--定义一个游标declare user_cur cursor for select

SQLSERVER游标的使用

declare @user_name varchar(100)  --定义一个游标  declare user_cur cursor for select user_name from [T_CORE_USER] where Bh is null--打开游标  open user_cur  while @@fetch_status=0  begin --读取游标    fetch next from user_cur into @user_name  begin    if (select count(*) from T_smes_qyxx where qy_mc = @user_name )<=1                 update  t1  set t1.BH = t2.QY_ID from [T_CORE_USER] t1,T_smes_qyxx t2  where t1.user_name    = @user_name and    t2.qy_mc    = @user_name              and t1.Bh is null               print @user_name    end  end close user_cur  --摧毁游标  deallocate user_cur 

热点排行