How to use cursor in sql server and update table
Microsoft Net Framework

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


Upcoming Articles
You may also read following recent Post
Copyright Future Minutes © 2015- 2024 All Rights Reserved.   Terms of Service  |   Privacy Policy |  Contact US|  Pages|  Whats new?
Update on: Dec 20 2023 05:10 PM