可能重复:
简单的更新语句,以便为所有行分配不同的值
有没有办法从子查询中选择一个随机值(如颜色)?这是我尝试过的,但每次运行都获得相同的值:
SELECT TOP (100) ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS ID,--Sequential number from 1 to ..
(SELECT TOP 1 color
FROM ( VALUES (0, 'Red'),
(1, 'Green'),
(2, 'Yellow') ) colors(id, color)
ORDER BY NEWID() ) AS RandomColor
FROM sys.all_columns ac1
CROSS JOIN sys.all_columns ac2
但如果我单独运行这件作品,我会得到不同的颜色:
SELECT TOP 1 color
FROM ( VALUES (0, 'Red'),
(1, 'Green'),
(2, 'Yellow') ) colors(id, color)
ORDER BY NEWID()