Tag Info

New answers tagged

0

The issue that you are facing is that, even though UDFs do run per-row, the state of the data, as far as that particular UPDATE statement is concerned, has not changed yet. And it won't register any changes until the statement completes successfully. This is not to be confused with transaction scope. If you have multiple statements within a transaction, ...


1

(You edited your question, so now I'm editing my answer) Stop using a UDF for it. Do it all in one hit like this: WITH Numbered AS ( SELECT *, ROW_NUMBER() OVER (PARTITION BY UID ORDER BY UID) AS DupeNum FROM theTable ) UPDATE Numbered SET UID = UID + '_' + CAST(DupeNum AS VARCHAR(10)) WHERE DupeNum > 1; By doing it all at once, you will avoid ...



Top 50 recent answers are included