---------------随机数种子-------
declare @seed int
declare @seedtime smalldatetime
declare @seednum int
--------------------声明游标----------
declare cur_gs scroll cursor for select 公司编码 from 公司维度表
declare cur_SBBM scroll cursor for select 设备编码 from 设备维度表
declare cur_SGYY scroll cursor for select 事故原因编码 from 事故原因维度表
declare cur_SGDJ scroll cursor for select 事故等级编码 from 事故等级维度表
declare cur_HBBM scroll cursor for select 航班编码 from 航班维度表
------------------打开游标-----------------------
open cur_gs
open cur_SBBM
open cur_SGYY
open cur_SGDJ
open cur_HBBM
------------------初始化随机种子----------------
set @seedtime='2000-1-1'
while @seedtime<'2004-1-1'
begin
set @seed=convert(int,@seedtime)+datepart(millisecond,getdate())
set @seednum=convert(int,rand(@seed)*10000)%33+1
----------------金额数据--------
set @人次=(@seednum+30)%9+@seed%3
set @损失金额=@seednum*200+@seed
----------------代码数据-------
fetch next from cur_gs into @公司编码
if @@fetch_status=-1 fetch first from cur_gs into @公司编码
fetch next from cur_SBBM into @设备编码
if @@fetch_status=-1 fetch first from cur_SBBM into @设备编码
fetch next from cur_SGYY into @事故原因编码
if @@fetch_status=-1 fetch first from cur_SGYY into @事故原因编码
fetch next from cur_SGDJ into @事故等级编码
if @@fetch_status=-1 fetch first from cur_SGDJ into @事故等级编码
fetch next from cur_HBBM into @航班编码
if @@fetch_status=-1 fetch first from cur_HBBM into @航班编码
-----------------------模拟数据生成----------------------
set @时间=@seedtime
insert into 航空事故和航空器事实表
(时间,设备编码,公司编码,事故原因编码,事故等级编码,航班编码,人次,损失金额)
values(@时间,@设备编码,@公司编码,@事故原因编码,@事故等级编码,@航班编码,@人次,@损失金额)
set @seedtime=@seedtime+1
end
----------------------数据生成结束,关闭游标------------
close cur_gs
close cur_SBBM
close cur_SGYY
close cur_SGDJ
close cur_HBBM
open cur_gs
open cur_SBBM
open cur_SGYY
open cur_SGDJ
open cur_HBBM
---------------随机数种子-------
declare @seed int
declare @seedtime smalldatetime
declare @seednum int
--------------------声明游标----------
declare cur_gs scroll cursor for select 公司编码 from 公司维度表
declare cur_SBBM scroll cursor for select 设备编码 from 设备维度表
declare cur_SGYY scroll cursor for select 事故原因编码 from 事故原因维度表
declare cur_SGDJ scroll cursor for select 事故等级编码 from 事故等级维度表
declare cur_HBBM scroll cursor for select 航班编码 from 航班维度表
------------------打开游标-----------------------
open cur_gs
open cur_SBBM
open cur_SGYY
open cur_SGDJ
open cur_HBBM
------------------初始化随机种子----------------
set @seedtime='2000-1-1'
while @seedtime<'2004-1-1'
begin
set @seed=convert(int,@seedtime)+datepart(millisecond,getdate())
set @seednum=convert(int,rand(@seed)*10000)%33+1
----------------金额数据--------
set @人次=(@seednum+30)%9+@seed%3
set @损失金额=@seednum*200+@seed
----------------代码数据-------
fetch next from cur_gs into @公司编码
if @@fetch_status=-1 fetch first from cur_gs into @公司编码
fetch next from cur_SBBM into @设备编码
if @@fetch_status=-1 fetch first from cur_SBBM into @设备编码
fetch next from cur_SGYY into @事故原因编码
if @@fetch_status=-1 fetch first from cur_SGYY into @事故原因编码
fetch next from cur_SGDJ into @事故等级编码
if @@fetch_status=-1 fetch first from cur_SGDJ into @事故等级编码
fetch next from cur_HBBM into @航班编码
if @@fetch_status=-1 fetch first from cur_HBBM into @航班编码
-----------------------模拟数据生成----------------------
set @时间=@seedtime
insert into 航空事故和航空器事实表
(时间,设备编码,公司编码,事故原因编码,事故等级编码,航班编码,人次,损失金额)
values(@时间,@设备编码,@公司编码,@事故原因编码,@事故等级编码,@航班编码,@人次,@损失金额)
set @seedtime=@seedtime+1
end
----------------------数据生成结束,关闭游标------------
close cur_gs
close cur_SBBM
close cur_SGYY
close cur_SGDJ
close cur_HBBM
open cur_gs
open cur_SBBM
open cur_SGYY
open cur_SGDJ
open cur_HBBM