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
 SQL Server Development (2000)
 Should I use a cursor or not - If not what process

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-06-11 : 10:17:18
Kevin writes "I have a table that is made up of 2 unique types of rows say ROW type1's and ROW type2's. What I must do is walk through my table comparing my current row with the prior row. If I have a ROW type 1 followed by a ROW type 2. I want to compare the current with the prior. If the key information is the same between the 2. I want to take the information from my Type 1 record and update the current record (which is a type 2) with this information.
If I compare the 2 rows and thet are both type 1's. I want to
advance one row were my current is now my prior and I have a new current record etc.
I have been looking at using a cursor type solution but unfortunately I am not getting enough info out of my text book or the ON-line books to try and satisfy this problem.
Is using a cursor the proper way to go or are there other solutions available?
Thanks
Kevin"

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-06-11 : 10:21:56
There is a set based solution to this that will (most likely) perform much better than a cursor. Please post the DDL of your table (CREATE TABLE statement) and the DML (INSERT statements) to populate it with sample data. If I understand your need correctly, I can show you how to do this with one UPDATE statement.

<O>
Go to Top of Page
   

- Advertisement -