Refer :
http://blog.sqlauthority.com/2007/01/01/sql-server-simple-example-of-cursor/[
^]
Simple example(This sample taken from above reference)
Selecting Account Id Using CURSOR
DECLARE @AccountID INT
DECLARE @getAccountID CURSOR
SET @getAccountID = CURSOR FOR
SELECT Account_ID
FROM Accounts
OPEN @getAccountID
FETCH NEXT
FROM @getAccountID INTO @AccountID
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @AccountID
FETCH NEXT
FROM @getAccountID INTO @AccountID
END
CLOSE @getAccountID
DEALLOCATE @getAccountID
Try:
update Table1 set serialnum = b.row1 from Table1 as a inner JOIN
(select itemcode,ROW_NUMBER() OVER(PARTITION BY icode ORDER BY icode DESC) as row1 from Table1) as b
on a.itemcode = b.itemcode