Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I am using the follwing code in a stored procedure to pull in data using another stored procedure:
DECLARE @associate_no intSELECT @associate_no = (select associate_no from tx_xref where category = 'E' and type = 4 and customer_no = @customer_no)Insert #t1(log_date, log_user, log_activity_type, log_contact_type, log_notes, log_amount, log_activity_no)Exec lp_customer_log @customer_no = @associate_no
This doesnt work when the "select associate_no from tx_xref..." statement returns more than one value. Is there way to loop this so that the lp_customer_log stored procedure is run for every record returned in this statement?Many thanks in advance...ThanksP
iminore
Posting Yak Master
141 Posts
Posted - 2005-07-08 : 08:46:08
Assuming associate_no is unique in ts_ref:DECLARE @associate_no intSET @associate_no = (select min(associate_no) from tx_xref where category = 'E' and type = 4 and customer_no = @customer_no)while @associate_no is not null begin Insert #t1(log_date, log_user, log_activity_type, log_contact_type, log_notes,log_amount, log_activity_no)Exec lp_customer_log @customer_no = @associate_noSET @associate_no = (select min(associate_no) from tx_xref where category = 'E' and type = 4 and customer_no = @customer_no and associate_no > @associate_no)end
waxdart23
Starting Member
33 Posts
Posted - 2005-07-08 : 09:14:31
Many thanks iminore. Worked a treat.ThanksP
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2005-07-08 : 09:18:34
A good alternative to Cursor MadhivananFailing to plan is Planning to fail