我对 SQL 和存储过程很陌生,我有点卡住了 - 所以任何帮助将不胜感激
我如何循环遍历每一行并为其分配我生成的随机值?
这是我的存储过程:
CREATE PROCEDURE StoredProc8
AS
BEGIN
DECLARE @total INT
DECLARE @Count INT = 0
DECLARE @Random INT = 0
SELECT @total = COUNT(CustomerID) FROM Customers
WHILE(@Count<= @total)
BEGIN
SELECT @Random = 2 * RAND()
EXEC ('update Customers set col1= ' + @Random )
SELECT @Count = @Count+1
END
END