I know that instead of cursor we can have the tables updated with different queries but I wanted to try using cursor so as to have a knowledge on cursor This was what I was trying I have inserted a new column which has null values instead of null I wanted to update that column based on the title column here what I used the query but I am unable to update the table can someone suggest a solution for this.
Declare @Title varchar(max)
Declare @Department varchar(max)
Declare Department_Cursor Cursor
For
Select Title, Department
from Sample_table
Open Department_Cursor
Fetch Next From Department_Cursor Into @Title, @Department
While @@fetch_status = 0
Begin
Update sample_table
Set @Department = 'Production'
where @Title = '%Production%'
Fetch Next From Department_Cursor Into @Title, @Department
End
Close Department_Cursor
Deallocate Department_Cursor