当前位置: 代码迷 >> SQL >> SQLSERVER游标的施用
  详细解决方案

SQLSERVER游标的施用

热度:88   发布时间:2016-05-05 12:27:13.0
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 
  相关解决方案