12,300,379 members (28,732 online)
Rate this:
Please Sign up or sign in to vote.
See more:
hello guys, i need help Smile |

i have a table like this

itemcode itemiicode itemordercode serialnum cpserialnum
4 2 4 21 21
5 2 5 -1 -1
6 3 6 14 14
7 4 7 15 15
8 5 8 41 41
9 6 9 72 72
10 6 10 -1 -1
11 6 11 -1 -1

i want result like below table using Cursors

itemcode itemiicode itemordercode serialnum cpserialnum
4 2 4 21 21
5 2 5 -1 21
6 3 6 14 14
7 4 7 15 15
8 5 8 41 41
9 6 9 72 72
10 6 10 -1 72
11 6 11 -1 72

itemcode is the primary key
Using Cursors we have to update the table

Please Help
Thanks and Regards
Harsha
Posted 15-Nov-12 0:55am
Comments
n.podbielski 15-Nov-12 7:07am

Don't use cursors. And don't expect people in CP to do work for you.
Harsha Dev 15-Nov-12 7:22am

hmm ok podbielski but i have to complete this task in company so oly asking help and i am new to cursors :)

## 1 solution

Rate this:
Please Sign up or sign in to vote.

## Solution 1

I am not sure what logic you have put for calculating the last column, but here is an example of using the cursor and updating the table:
```DECLARE @field1 int;
DECLARE @field3 int;
DECLARE c1 CURSOR FOR field1, field3 from table1 for update of field3;
open c1;
FETCH NEXT FROM c1 into @field1, @field3
WHILE @@FETCH_STATUS = 0
BEGIN
-- add the logic you want to add..example
SET @field3 = @field3 + 20
UPDATE table1 set field3  = @field3 where current of c1
FETCH NEXT FROM c1 into @field1, @field3

END
CLOSE c1;
DEALLOCATE c1;```

try doing this without cursors if you can
Comments
Harsha Dev 15-Nov-12 7:20am

Thanks Om Prakash :) Here i have not used logic but i need to update the last column with same seraialnum i need to use cursors for swapping or holding variables and get the result

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 Karthik Bangalore 285 Garth J Lancaster 260 Richard MacCutchan 175 BillWoodruff 120 Sergey Alexandrovich Kryukov 118
 OriginalGriff 9,787 ppolymorphe 5,881 CHill60 5,552 Karthik Bangalore 5,341 Richard MacCutchan 5,099

Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100