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?
Basically, I want to restart the counter when it hits a new TempDocNumber
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
You could just create your insert like this:
No
UPDATEneeded.For SQL Server 2000
Assuming that DetailID is an identity column, you can try the following (again, no
UPDATEneeded):