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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop in Stored Procedure 1

Status
Not open for further replies.

Elton1984

Programmer
Mar 8, 2004
16
Hiz all,
Reallie in need of some help here..
My stored procedure onli update the last record of the DB.

DECLARE @prdtID varchar(10)
SELECT @prdtID = a.PrdtCode FROM tblPrdt a LEFT OUTER JOIN tblLoan b ON a.PrdtCode = b.PrdtCode WHERE (b.LoanIndex IS NULL)
UPDATE tblPrdt
SET PrdtStatus = 'On Loan'
WHERE PrdtCode = @prdtID

I know that i am needed to input a loop somewhere in my codes but i seriously have no idea of where and how to do it.. Ermz anyone haf any ideas?

Thanx in advance
Elton Wong
 
No need for a loop. Update all applicable product statuses at once. How does this work for you? Good luck!

Code:
UPDATE tblPrdt
SET PrdtStatus = 'On Loan'
FROM tblPrdt a
  LEFT OUTER JOIN tblLoan b
    ON a.PrdtCode = b.PrdtCode
WHERE (b.LoanIndex IS NULL)

--Angel [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top