title: How to use update cursor dynamicaly
body: <p>I need to encode my data by this rule:  according to the length of current word I change the letters of the word and update it in the same table, I'm not sure how to use the UPDATE cursor in that case, would love to get examples.
  This is my current code:</p>
  
  <pre><code>DECLARE @name varchar(30)       
  DECLARE currentCursor  CURSOR for select Lastname from contact;
  OPEN  currentCursor
  FETCH NEXT FROM currentCursor INTO @name                    
              Declare @Length int =0;     
              Declare @newName varchar(30)
              select @Length =   LEN(@name);  
               --     DECLARE currentCursor2  CURSOR for update
              while @Length &gt;0
                  begin
                      set @newName = concat( @newName,  CHAR(CAST(27 * RAND() + 224 AS INT)) )
                      set @Length = @Length -1;                                                           
                 end
              --  FETCH NEXT FROM currentCursor2 INTO @newName  
                  update contact 
                  set LastName = @newName
                  where lastname = @name
  CLOSE currentCursor;
  DEALLOCATE currentCursor
  </code></pre>