Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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
Posted

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);
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

this worked for me .
it was because i needed to initialize @po_no_concted to @po_no_concted=''
 
Share this answer
 
i think theres something about concateation that i dont know.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Mar-15 1:46am    
I don't want to look at you other "answers", but if they are like this one, please remove them. This one is not the answer; and such posts are considered as abuse. Use comments and/or "Improve question" instead.
—SA
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
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Mar-15 1:47am    
Please stop it. Don't post things like that as answers.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900