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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Looping through results in a stored procedure

Author  Topic 

Skydolphin
Starting Member

43 Posts

Posted - 2003-07-11 : 13:30:43
Hi All,

I am trying to write a stored procedure that runs a simple select statement, gets the values of certain fields in the table and inserts them along with some other fields into a new table. The queries run but the insert only happens for the last record returned from the select. How can I loop through the results inserting a record for each one?

All of the other fields are either set using a declare or are passed in the procedure.

BEGIN
Select @strBarcode = Barcode, @strLID = LID from TableName

Insert into newTable(Drawing_Type, Barcode, Sheet_Dim, Page, Description, Date, LID, Notes, SCovr, SIndx, SPlan, SProf, SDet, SNote, Station_No, Original_Page, Category_No, Dwg_No, Type, FNew, FRest, FPark, FExist) values
(@strDrawing_Type, @strBarcode, @strSheet_Dim, @strPage, @strDescription, @strDate, @strLID, @strNotes, @strSCovr, @strSIndx, @strSPlan, @strSProf, @strSDet, @strSNote, @strStation_No, @strOriginal_Page, @strCategory_No, @strDwg_No, @strType, @strFNew, @strFRest, @strFPark, @strFExist)
END

Any ideas would be greatly appreciated.

Thanks

Rhonda

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-07-11 : 13:41:42
Duplicate post:
[url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=27685[/url]

Tara
Go to Top of Page
   

- Advertisement -