Sqlserver Sql随机函数+循环语句

--DECLARE @find INT

--WHILE(set @find  = 1;@find<=19;@find++){
--UPDATE EM_TOTAL_ANALYZE SET SO2_ = cast( floor(rand()*20) as int),NO_ = cast( floor(rand()*20) as int),Comi_ = cast( floor(rand()*20) as int) where ID_ = @find

--}

declare @i int
set @i=1
while @i<20
begin
UPDATE EM_TOTAL_ANALYZE SET SO2_ = cast( (floor(rand()*20)+1) as int),NO_ = cast( (floor(rand()*20)+1) as int),Comi_ = cast( (floor(rand()*20)+1) as int) where ID_ = @i
set @i=@i+1
end

--UPDATE EM_TOTAL_ANALYZE SET SO2_ = cast( floor(rand()*20) as int),NO_ = cast( floor(rand()*20) as int),Comi_ = cast( floor(rand()*20) as int) where ID_ = 2
--SELECT cast( floor(rand()*20) as int) FROM EM_TOTAL_ANALYZE

猜你喜欢

转载自applesmel.iteye.com/blog/2264713