Fill SQL Column with one of three values according to a Row Number
Once again experiments and tests. I added a new column to the existing table and needed to fill it with different values.
The code below fills the field Color with one of 3 values. It depends on ROW_NUMBER value
SET @randomIndex = ABS(CHECKSUM(NEWID())) % 3 + 1;
;WITH CTE AS (
SELECT
COLOR,
ROW_NUMBER() OVER (ORDER BY ID) AS RowNum
FROM
vLogView
)
UPDATE CTE
SET COLOR = CASE (RowNum % 3)
WHEN 0 THEN 'Blau'
WHEN 1 THEN 'Grün'
ELSE 'Schhwartz'
END;