sql中的嵌套循环怎么写?

atlasGS 2003-10-30 04:01:51
如题!
...全文
489 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
atlasGS 2003-10-30
  • 打赏
  • 举报
回复
〉=1
txlicenhe 2003-10-30
  • 打赏
  • 举报
回复
select @ddxc=count(*) from tblmatorderdata where 订购单编号=@newstring
返回值是多少啊?是不是只有一条啊?
atlasGS 2003-10-30
  • 打赏
  • 举报
回复
第二个循环只能执行一次!!!!
不知是啥原因!!!
atlasGS 2003-10-30
  • 打赏
  • 举报
回复
CREATE PROCEDURE usp_bdfd_print
@string varchar(250),@strnum int,@cgrq char(10)
as
declare @newstring varchar(250),@i int,@x int,@wlbh char(20),@ddxc int,@x1 int
set @x=0
while @x<@strnum
begin
set @i=charindex('-',@string+'-')
set @x=@x+1
set @newstring=left(@string,@i-1)
set @string=substring(@string,@i+1,500)
select @wlbh=物料编号 from tblmatorderdata where 订购单编号=@newstring
update tblmatordercount
set 采购日期=@cgrq,
已发单标记=1
where 订购单编号=@newstring
insert tblrecivematdata (订购单编号,订单项次,物料编号,到货日期,到货数量,检验日期,操作员,退货日期,退货数量,入库数量,入库日期,状态标记)
select 订购单编号,订单项次,'M///','/',0,'/','/','/',0,0,'/',0 from tblmatorderdata where 订购单编号=@newstring
select @ddxc=count(*) from tblmatorderdata where 订购单编号=@newstring
set @x1=0
while @x1<@ddxc
begin
set @x1=@x1+1
select @wlbh=物料编号 from tblmatorderdata where 订购单编号=@newstring and 订单项次=@x
update tblrecivematdata
set 物料编号=@wlbh
where 订购单编号=@newstring and 订单项次=@x
end
end
if @@error<>0
rollback
GO
txlicenhe 2003-10-30
  • 打赏
  • 举报
回复
楼主的意思?
写个大概看看?
atlasGS 2003-10-30
  • 打赏
  • 举报
回复
我觉得不妥:
我现在这个循环@i产生的变量,@j要用到。
LoveSQL 2003-10-30
  • 打赏
  • 举报
回复
declare @i int,@j int

while @i <=100
begin
while @j <= 10
begin
....
end
...
end
银狐被占用 2003-10-30
  • 打赏
  • 举报
回复
同意txlicenhe(马可)
txlicenhe 2003-10-30
  • 打赏
  • 举报
回复
while @i <=100
begin
while @j <= 10
begin
....
end
...
end

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧