Cursor SQL 2012

steven
steven used Ask the Experts™
on
We are currently load data to tables from a spread sheet.  The first table to load the "master"  is a one to many relationship.  To start we have a cursor that grabs the items to load.  IT then loads the master table inside of that cursor is another that pulls the many columns to populate using the ITEM from the outside cursor.  The inside cursor only runs one time and exits?  We pass it the item value from the outter cursor, the inside cursor pulls 8 values, for the ONE item value, but it will only load the first pass and exit.  

I am not real good with sql, so why doesn't it run the full eight times and then exit.  (Some will have as little as five runs)
BomInsert.sql
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
HuaMin ChenProblem resolver

Commented:
Check the data/record within the loop, to see what records are being scanned in that.
HuaMin ChenProblem resolver

Commented:
Within the loop, you can also have temp table to hold the data returned, to know what is happening.
Business Intelligence Developer and Analyst
Top Expert 2015
Commented:
Hi ,

After

FETCH NEXT FROM rout  INTO  @job,@item_num, @OperationNum, @Work_Center,@CONTROLPOINT
WHILE @@FETCH_STATUS = 0

statement you have mentioned

two begin clause

I think you have 5 begin clause and only 4 end clause.

Please remove the duplicate begin. As per my idea wrong begin is placed after the statement i wrote above.

I have attached screen shot
Capture.PNG
stevendeveloper

Author

Commented:
I added a table to see what data was being captured and it ran as i expected it to the joins were the issues, on the update and inserts.  Thanks for all the advice i appreciate it.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial