急急!本人急需生成模拟数据的sql语句!

sunssc 2003-06-20 05:24:58

刚接了一个数据仓库的项目,需要模拟一部分业务数据,进行多维分析!
下班前需要做出结果!
谢谢!
sunssc@163.com
...全文
160 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunssc 2003-06-20
  • 打赏
  • 举报
回复
to blactte(想认识我吗?在靠近一点!)
谢谢老兄就是满了一点!!
愉快的登山者 2003-06-20
  • 打赏
  • 举报
回复
insert yourtable
select '1','2'...
union
select '3','2'...
...
blactte 2003-06-20
  • 打赏
  • 举报
回复
up
blactte 2003-06-20
  • 打赏
  • 举报
回复
create procedure sp_data_jzxttl
as

truncate table 航空事故和航空器事实表
---------------变量声明--------------
declare @公司编码 varchar(50)
declare @设备编码 varchar(50)
declare @事故原因编码 varchar(50)
declare @事故等级编码 varchar(50)
declare @航班编码 varchar(50)
declare @时间 smalldatetime
declare @人次 int
declare @损失金额 int

---------------随机数种子-------
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

deallocate cur_gs
deallocate cur_SBBM
deallocate cur_SGYY
deallocate cur_SGDJ
deallocate cur_HBBM

return
blactte 2003-06-20
  • 打赏
  • 举报
回复
create procedure sp_data_jzxttl
as

truncate table 航空事故和航空器事实表
---------------变量声明--------------
declare @公司编码 varchar(50)
declare @设备编码 varchar(50)
declare @事故原因编码 varchar(50)
declare @事故等级编码 varchar(50)
declare @航班编码 varchar(50)
declare @时间 smalldatetime
declare @人次 int
declare @损失金额 int

---------------随机数种子-------
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

deallocate cur_gs
deallocate cur_SBBM
deallocate cur_SGYY
deallocate cur_SGDJ
deallocate cur_HBBM

return

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧