Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cursor syntax

Status
Not open for further replies.

TomBarrand

Programmer
Joined
Aug 9, 2000
Messages
162
Location
GB
I intend to use cursors to solve a problem that I have, but I am unfamiliar with them. What I want to do is as follows:

1. Call a stored procedure from an external app and pass a value into @POLineNo.
2. Delete records from FOB_Size table that meet the criteria below.
3. Select FOB_No and FOB_Quantity from FOB
4. Get the first FOB record and hold the details in @FOBNo and @FOBQTY
5. Select Size_No and Ratio from Size
6. Get the first Size_No and Ratio and hold them in @SizeNo and @Ratio
7. Do the following calculation, @SizeQTY = (@Ratio/100) * @FOBQTY
8. Insert a record into FOB_Size with the values stored in @FOBNo, @SizeNo and @SizeQTY
9. As long as you are not at the end of the SizeNo recordset do points 5 to 8 again for the next Size record
10. When the end of the Size_No recordset is reached for the current FOB_No get the next FOB_No in the FOB recordset and follow steps 5 to 8 again

Can anyone help me with the syntax? What I have got so far is below.

Thanks

CREATE PROCEDURE sp_AddAllSizes
@POLineNo INT

AS
DELETE FOB_Size
FROM FOB_Size, FOB
WHERE FOB.FOB_No = FOB_Size.FOB_No AND FOB.Purch_Ord_Line_No = @POLineNo

DECLARE FOBNo_Curs CURSOR
FOR
SELECT FOB_No, FOB_Quantity
FROM FOB
WHERE Purch_Ord_Line_No = @POLineNo
FOR READ ONLY
GO

DECLARE @FOBNo INT, @FOBQTY INT

FETCH NEXT FROM FOBNo_Curs into @FOBNo, @FOBQTY
WHILE @@Fetch_Status = 0 BEGIN

DECLARE @SizeNo INT

END
CLOSE FOBNo_Curs
return
GO


SELECT Size_No, Ratio
FROM SIZE
WHERE Purch_Ord_Line_No = @POLineNo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top