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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-06-11 : 10:11:50
|
| Kannan writes "I have a Store Procedure which accepts a keyword as a Parameter. With that keyword i have to Query the master which holds details about the keywords.For instance i have a keyword 'Data' and my master table has two or more records matching to the keyword 'Data', i need to Loop through the result set and i need to insert the corresponding ID in the master table to a new results table. How do i loop through records?Kindly give me a solution for this,right now i have used cursors.I have SQL 7 with Windows 2000.Following is the Query,select a.docID from tbldocumentmaster a,tbldocumentkeywords b where a.docID=b.docID and b.keywords=@keyword--where @keyword is the parameter which i receive to the Store procedure.For the above query i get more than one record. So how do i loop through the records and insert the ID's to a new table." |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2002-06-11 : 10:18:29
|
| Is there a specific need for an iterative solutions? Generally SQL Server performs much better with a set based approach. You can INSERT into your 'new results table' the set of data exposed by your select statement all in one operation...<O> |
 |
|
|
dsdeming
479 Posts |
Posted - 2002-06-12 : 07:50:34
|
| By all means, use set based code if you can. If you can't, then cursors are the method for looping through results and acting on the individual rows. The are other methods of mimicking cursor functionality ( using TOP 1 and an aggregate function ), but I don't think they're any more efficient that cursors. |
 |
|
|
|
|
|