Click here to Skip to main content
15,920,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
declare @code varchar(50)
declare @new varchar(50)

declare udates cursor for 

SELECT DISTINCT E.C_EmpCode,replace(e.C_EmpCode,'0','100') FROM Tbl_Emp_Mst E
JOIN Tbl_User_Info U ON U.C_Code=E.C_EmpCode
JOIN Tbl_UserRights US ON US.c_userid=E.C_EmpCode
JOIN Tbl_FS_Mst FS ON FS.C_EmpNo=FS.C_EmpNo
JOIN tbl_fs_emp_rel FSM ON FSM.c_emp_code=E.C_EmpCode
JOIN FSHEIRARCHY FSH ON FSH.empcode=E.C_EmpCode

open updates
fetch next from updates into @code,@new
while @@FETCH_STATUS=0
begin
update Tbl_Emp_Mst set C_EmpCode=@new where C_EmpCode=@code
--update Tbl_FS_Mst set C_EmpNo=@new where C_EmpNo=@code
update tbl_fs_emp_rel set c_emp_code=@new where c_emp_code=@code
update fsheirarchy set empcode=@new where EmpCode=@code

update Tbl_User_Info set C_Code=@new where C_Code=@code
update Tbl_User_Info set C_UserID=@new where C_UserID=@code
update Tbl_User_Info set C_Password=@new where C_Password=@code

update Tbl_UserRights set c_userid=@new where c_userid=@code

fetch next from updates into @code,@new
end
close updates
deallocate updates

error while executing script.
SQL
Msg 16916, Level 16, State 1, Line 6
A cursor with the name 'updates' does not exist.
Msg 16916, Level 16, State 1, Line 14
A cursor with the name 'updates' does not exist.
Msg 16916, Level 16, State 1, Line 30
A cursor with the name 'updates' does not exist.
Msg 16916, Level 16, State 1, Line 31
A cursor with the name 'updates' does not exist.
Posted
Updated 17-Mar-15 20:21pm
v2
Comments
Thanks7872 18-Mar-15 2:45am    
Title was invented to have a quick glance at underlying content. Such title doesn't make sense at all. It should be relevant to your question.

There's the error:
SQL
declare udates cursor for
declare updates cursor for
 
Share this answer
 
You have declared Cursor name as udates but with in your CURSOR you have used updates

Using CURSOR is Bad Practice in SQL Server .It causes Performance Issues .

Please Refer it.

http://stackoverflow.com/questions/58141/why-is-it-considered-bad-practice-to-use-cursors-in-sql-server[^]

SQL Server DO's and DONT's[^]

Alternate for CURSOR

http://www.dotnet-tricks.com/Tutorial/sqlserver/IT5G180512-SQL-Server-Cursor-Alternatives.html[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900