DECLARE @Count int
DECLARE @Sum int
DECLARE @Num int
SELECT @Count=100,@Sum=0
WHILE (@Count>0)
BEGIN
SELECT @Num=CAST(RAND()*100 AS INT)
SELECT @Sum=@Sum+@Num,@Count=@Count-1
END
PRINT CONVERT(NVARCHAR(10),@Sum)
DECLARE @Count int
DECLARE @Sum int
DECLARE @Num int
SELECT @Count=100,@Sum=0
WHILE (@Count>0)
BEGIN
SELECT @Num=CAST(RAND()*100 AS INT)
SELECT @Sum=@Sum+@Num,@Count=@Count-1
END
PRINT CONVERT(NVARCHAR(10),@Sum) 才