--循环
WHILE @i<40
BEGIN
……
end
--随机数
SET @money=rand()*100000
例子:
DECLARE @i INT
DECLARE @money MONEY
DECLARE @month int
SET @i=1
WHILE @i<40
BEGIN
SET @money=rand()*100000
SET @month=-RAND()*10
INSERT INTO Charge
(ID
,Date
,ChargeTypeID
,ChargeTypeName
,Money
,Remark
,CreatedBy
,CreatedTime)
VALUES
(48
,dateadd(month,@month,getdate())
,1
,''
, @money
,N'花了'+CONVERT(VARCHAR,@money)
,'KK'
,GETDATE())
SET @i=@i+1 --不要忘记
end