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 |
|
zwheeler
Starting Member
25 Posts |
Posted - 2012-01-31 : 17:23:37
|
| HiI have a cursor and I am trying to understand it. I have a couple of questions. here is the beginning of the cursorDECLARE Cur1 CURSOR FAST_FORWARD FOR SELECT fk_property_id, date_property_event, date_age_out FROM stg_mddr_assignment ORDER BY fk_property_id, date_property_event, date_age_outDECLARE @pid int, @date_start datetimeDECLARE @pid_A int, @date_start_A datetime, @date_end_A datetimeDECLARE @pid_B int, @date_start_B datetime, @date_end_B datetimeOPEN Cur1FETCH NEXT FROM Cur1 INTO @pid_A, @date_start_A, @date_end_AFETCH NEXT FROM Cur1 INTO @pid_B, @date_start_B, @date_end_BQuestion:FETCH NEXT FROM Cur1 INTO @pid_A, @date_start_A, @date_end_AFETCH NEXT FROM Cur1 INTO @pid_B, @date_start_B, @date_end_BWhen the sql is executed for Cur1 does this contain the same rows or does the first fetch get row 1 and puts row 1 data into _A variables and the second fetch gets row 2 data and puts it into variables _Bor do they both contain the same data i.e. Row1 Thanks in advance |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2012-01-31 : 17:45:59
|
quote: the first fetch get row 1 and puts row 1 data into _A variables and the second fetch gets row 2 data and puts it into variables _B
That. FETCH NEXT moves the row pointer of the cursor as long as there are rows to be fetched. |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2012-01-31 : 18:10:56
|
| I hope your 2nd question is: how do I rewrite this without using a cursor?Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-31 : 19:09:45
|
| seems like whole exercise is to somekind of comparison between consecutive rows. why should you use cursor for that?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|