游标问题,我认为我错过的东西我是T Sql的新手 [英] Cursor Problem ,I Think Theres Something I Am Missing I Am New To T Sql

查看:58
本文介绍了游标问题,我认为我错过的东西我是T Sql的新手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

declare @t_Ord_e_id table (order_entry_id numeric(18,0) ,po_no numeric(18,0));
			

	declare cur_ord_ent_id cursor for 
	select distinct  order_entry_id from order_entry_details 
	
	 declare @O_ent_id varchar(50);
	 declare @po_no varchar(60);
	 declare @po_no_concted varchar(100);
	 open cur_ord_ent_id
	 fetch next from cur_ord_ent_id
	 into @O_ent_id
	 while @@FETCH_STATUS=0
		 begin
				 declare cur_po_no cursor for
				 select distinct po_no from order_entry_details where order_entry_id=@O_ent_id
				
				 open cur_po_no
				 fetch next from cur_po_no
				 into @po_no
				 while @@FETCH_STATUS=0
					 begin
						 set @po_no_concted=@po_no_concted+ ','+@po_no
						 print @po_no
						 print @po_no_concted
						 fetch next from cur_po_no
						 into @po_no
					 end
				 close cur_po_no
				 deallocate  cur_po_no
			 insert into @t_Ord_e_id (order_entry_id,po_no)	 
			 values(@O_ent_id,@po_no_concted)
			 
			 fetch next from cur_ord_ent_id
			 into @O_ent_id
		 end 
	 close cur_ord_ent_id
	 deallocate cur_ord_ent_id

<打印内部@po_no的
但@po_no_concted没有错误,它打印出任何内容。请指导我这个


in inner @po_no is printed but there no error for @po_no_concted nither it prints anything of it. please guide me on this

推荐答案

declare @t_Ord_e_id table (order_entry_id numeric(18,0) ,po_no numeric(18,0));
			
 
	declare cur_ord_ent_id cursor for 
	select distinct  order_entry_id from order_entry_details 
	
	 declare @O_ent_id varchar(50);
	 declare @po_no varchar(60);
	 declare @po_no_concted varchar(100);
set @po_no_concted=''
	 open cur_ord_ent_id
	 fetch next from cur_ord_ent_id
	 into @O_ent_id
	 while @@FETCH_STATUS=0
		 begin
				 declare cur_po_no cursor for
				 select distinct po_no from order_entry_details where order_entry_id=@O_ent_id
				
				 open cur_po_no
				 fetch next from cur_po_no
				 into @po_no
				 while @@FETCH_STATUS=0
					 begin
						 set @po_no_concted=@po_no_concted+ ','+@po_no
						 print @po_no
						 print @po_no_concted
						 fetch next from cur_po_no
						 into @po_no
					 end
				 close cur_po_no
				 deallocate  cur_po_no
			 insert into @t_Ord_e_id (order_entry_id,po_no)	 
			 values(@O_ent_id,@po_no_concted)
			 
			 fetch next from cur_ord_ent_id
			 into @O_ent_id
		 end 
	 close cur_ord_ent_id
	 deallocate cur_ord_ent_id



这对我有用。

这是因为我需要将@po_no_concted初始化为@po_no_concted =''


this worked for me .
it was because i needed to initialize @po_no_concted to @po_no_concted=''


我认为这是关于串联的一些我不会知道。
i think theres something about concateation that i dont know.


我在网上找到@po_no_concted最初应该有一些价值申报后我没有申请
i found on web @po_no_concted should have some value initially and not null
after declaration i t i put this @po_no_concted

这篇关于游标问题,我认为我错过的东西我是T Sql的新手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆