title: Using a counter to increment a column number
body: <p>I need to increment a column (Counts) +1 for every NEW DocNumber. So if the DocNumber is the same for three columns, the counter will be 1,2,3 etc. Below is the code. I got it to the point where it will update the entire table, just not based on the same or different docnumbers. Can someone help me with the logic here?</p>
  
  <p>Basically, I want to restart the counter when it hits a new TempDocNumber</p>
  
  <pre><code>DECLARE @DocTable Table (DetailID FLOAT, TempDocNumber FLOAT, Counts INT)
  INSERT INTO @DocTable (DetailID, TempDocNumber, Counts)
  SELECT DetailID, DocumentNumber, 0 FROM ChargebackDetailTempTable
  
  
  declare @Counter int
  Set @Counter = 0
  Update @Doctable
  SET @Counter = counts = @Counter + 1
  
  -- start counter over when new tempdocnumber
  </code></pre>