DECLARE @v TABLE (x VARCHAR(50)) INSERT INTO @v VALUES -- list of strings that column will be updated with ('37845840'),('34879335'),('33879336'),('37855840'); DECLARE cursor1 CURSOR FOR SELECT <TABLE_ID> FROM <SOME_TABLE>; DECLARE @id INT; OPEN cursor1 FETCH NEXT FROM cursor1 INTO @id WHILE @@FETCH_STATUS=0 BEGIN UPDATE <SOME_TABLE> SET <UPDATED_COLUMN> = ( SELECT x FROM ( SELECT *, ROW_NUMBER()OVER(ORDER BY x ASC)rn FROM @v s ) a WHERE rn=CAST(rand() * (SELECT COUNT(*) FROM @v) AS INT)+1 ) WHERE <TABLE_ID>=@id FETCH NEXT FROM cursor1 INTO @id; END CLOSE cursor1 DEALLOCATE cursor1 |
<SOME_TABLE> – table name
<TABLE_ID> – id column in SOME_TABLE
<UPDATED_COLUMN> – column which is updated