How to use cursor, How to update table using cursor, How to get and set in cursor in MS Sql Server 2008,2008R2, 2012,2014
DECLARE @userid bigint
DECLARE @getAccountID CURSOR
SET @getAccountID = CURSOR FOR
SELECT Users_ID
FROM IE_User
OPEN @getAccountID
FETCH NEXT
FROM @getAccountID INTO @userid
WHILE @@FETCH_STATUS = 0
BEGIN
declare @email varchar(500)
set @email=(select LEFT(u.Email, CHARINDEX('@', u.Email) - 1) AS username from IE_User u where Users_ID=@userid)
update IE_User set LastName=@email where Users_ID=@userid
FETCH NEXT
FROM @getAccountID INTO @userid
END
CLOSE @getAccountID
DEALLOCATE @getAccountID
Share This with your friend by choosing any social account