• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
繁星
不要浪费时间
博客园    首页    新随笔    联系   管理    订阅  订阅

SQL 游标foreach 表


declare @auid int,@aulname varchar(20),@aufname varchar(20), @st char(2),@auinfo varchar(50)

declare auth_cur cursor for

select tp_id, nvarchar19

from AllUserData where
tp_ListId='85CD0CD4-D471-49D6-9765-FB3D27F136E2'

open auth_cur

fetch next from auth_cur into @auid,@aulname

while (@@fetch_status=0)

begin

--print cast(@aulname as decimal(10,4))

select cast(@aulname as decimal(10,4))

fetch next from auth_cur into @auid,@aulname

end

close auth_cur

deallocate auth_cur

 

 

 

------

fetch next from somain into @poid,@cpoid,@cexch_name
while (@@fetch_status<>-1)
begin
--set @autoid=(select isnull(max(autoid),0) from so_somain)+1
--set @autoid=isnull((select ifatherid from ufsystem.dbo.ua_identity where cacc_id='010' and cvouchtype='somain'),0)
--select @poid,@cpoid,@autoid
--set @autoid=(select count(*) from so_somain)+1
set @autoid=(select max(id) from so_somain)+1--08.18 byzzq
Insert Into SO_SOMain(cDefine14,cDefine15,id,cstcode,ddate,csocode,ccuscode,cdepcode,cexch_name,itaxrate,istatus,cmaker,cbustype,iverifystate)
values(@poid,cast(@poid as int),@autoid,'01',getdate(),@cpoid,'SZHL','HS1501','人民币',17,0,'zzq','委托代销',0)
update ufsystem.dbo.ua_identity set ifatherid=@autoid where cacc_id='115' and cvouchtype='somain'
fetch next from somain into @poid,@cpoid,@cexch_name
end
close somain
deallocate somain

posted @ 2016-07-02 21:19  ※繁星※  阅读(346)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3