title: HOW to use STUFF with UPDATE in SQL
body: <p>I have table with 3 column and field Data-Types is Decimal(38,0).
  so I want to update each row of my table . actually the length of number is not same as each other I mean some of them is 5 digit and some of them 7 digit but I want after 2 first digit insert '.' (Decimals) for example 123456 should be 12.3456</p>
  
  <p>my table is:</p>
  
  <pre><code>+-------------+-------+-------+
  | ID          |   X   |   Y   |
  +-------------+-------+-------+
  | 1200        | 321121| 345000| 
  | 1201        | 564777| 4145  | 
  | 1202        | 4567  | 121444| 
  | 1203        | 12747 | 789887| 
  | 1204        | 489899| 124778|
  +-------------+-------+-------+
  </code></pre>
  
  <p>and I want to change this :</p>
  
  <pre><code>+-------------+--------+--------+
  | ID          |   X    |   Y    |
  +-------------+--------+--------+
  | 1200        | 32.1121| 34.5000| 
  | 1201        | 56.4777| 41.45  | 
  | 1202        | 45.67  | 12.1444| 
  | 1203        | 12.747 | 78.9887| 
  | 1204        | 48.9899| 12.4778|
  +-------------+--------+--------+
  </code></pre>
  
  <p>my code is here :</p>
  
  <pre><code>Update [dbo].[UTM]
       SET [X] = STUFF([X],3,0,'.')
           [Y] = STUFF([X],3,0,'.')
  </code></pre>
  
  <p>and I try this :</p>
  
  <pre><code>BEGIN 
  DECLARE @COUNT1 int;
  DECLARE @COUNT2 int;
  DECLARE @TEMP_X VARCHAR(255);
  DECLARE @TEMP_Y VARCHAR(255);
  DECLARE @TEMP_main VARCHAR(255);
  
  SELECT @COUNT1 = COUNT(*) FROM [UTM1];
  SET @COUNT2 = 0;
  
      WHILE(@COUNT2&lt;@COUNT1)
      BEGIN
          SET @TEMP_main = (SELECT [id] from [UTM1] order by [id] desc offset @COUNT2 rows fetch next 1 rows only);
          SET @TEMP_X = (SELECT [X] from [UTM1] order by [id] desc offset @COUNT2 rows fetch next 1 rows only);
          SET @TEMP_Y = (SELECT [Y] from [UTM1] order by [id] desc offset @COUNT2 rows fetch next 1 rows only);
  
          UPDATE [dbo].[UTM1]
             SET [X] = CONVERT(decimal(38,0),STUFF(@TEMP_X,3,0,'.'))
                ,[Y] = CONVERT(decimal(38,0),STUFF(@TEMP_Y,3,0,'.'))
             WHERE [id] = @TEMP_main;
  
          SET @COUNT2 = @COUNT2  +  1
      END
  
  END
  </code></pre>