f_naderi
سه شنبه 29 مرداد 1392, 20:02 عصر
سلام
من یک store procedure دارم که بدین صورت است:
USE [TEST_DB]
GO
/****** Object: StoredProcedure [dbo].[CDR_Generator] Script Date: 08/20/2013 07:35:59 ب.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[CDR_Generator]
@indexInput int
AS
BEGIN
Declare @index bigint, @intRowCount1 int, @intRowCount2 int,@intRowCount3 int, @currentDate Date, @initialTime Time, @currentTime Time;
Declare @initialDate Date, @callDuration int, @calledParty bigint;
set @index=@indexInput;
set @intRowCount1='10';
set @intRowCount2='356';
set @intRowCount3=Rand()*15;
set @initialDate='2012/01/01';
set @initialTime='07:00';
set @currentTime=@initialTime;
set @currentDate=@initialDate;
--Deleting the data in the table
truncate table CDR;
While @intRowCount1 >=1 --For index
begin
declare @subscriberType float=Rand();
--if(@subscriberType<='0.76')
--begin
while @intRowCount2 >=1 --For Date
begin
set @currentDate=DATEADD(DAY, -1, @currentDate);
while @intRowCount3 >=1 -- For Time
begin
set @currentTime=DATEADD(Minute, Rand()*150, @currentTime);
set @callDuration=RAND()*30;
if(@callDuration>='10')
begin
set @callDuration=@callDuration*30+rand()*10;
end
if(Rand()>'0.7')
begin
if(@index<'900000')
set @calledParty=@index+Cast(rand()*1500 as int);
else
set @calledParty=@index-Cast(rand()*1500 as int);
end
else
set @calledParty=Cast(rand()*1000000 as int);
--insert into CDR (MSISDN, Call_Partner, Call_Date, Call_Time, Call_Duration, Location1, Location2)
insert into CDR (MSISDN, Call_Partner, Call_Date, Call_Time, Call_Duration) --, Call_Partner, Call_Date, Call_Time, Call_Duration, Location1, Location2)
Values(
(select dbo.MCI_Subscriber.MSISDN from MCI_Subscriber where ID=@index), --MSISDN
(select dbo.MCI_Subscriber.MSISDN from MCI_Subscriber where ID=@index + @calledParty),
(@currentDate),
(@currentTime),
(@callDuration)
)
set @intRowCount3=@intRowCount3-'1';
end
set @currentTime=@initialTime;
set @intRowCount3=Rand()*15;
set @intRowCount2=@intRowCount2-'1';
end
--end
--else
-- begin
-- print 'Price';
-- end
set @intRowCount2='356';
set @index=@index+1;
set @intRowCount1=@intRowCount1-'1';
set @initialDate='2012/01/01';
print @index;
end
END
وبرای تولید داده تصادفی برای جدول CDR است که دارای فیلدهای موجود در تصویر می باشد.حال می خواهم این store را کاملتر کنم بدین صورت که به ازای هر رکورد مقدار msisn را بگیرد و با توجه به سه رقم اول شماره موبایل استان را معلوم کند مثلا اگر پیش شماره 912 باشد کد استان تهران را از جدول region استخراج کند و در فیلد location1 ذخیره کند و سپس با توجه به استان انتخاب شده به صورت random یکی از شهرهای آن استان را انتخاب کند و سپس کد شهر را در فیلد location2 در جدول cdr قرار دهد
با تشکر109401109402109403
من یک store procedure دارم که بدین صورت است:
USE [TEST_DB]
GO
/****** Object: StoredProcedure [dbo].[CDR_Generator] Script Date: 08/20/2013 07:35:59 ب.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[CDR_Generator]
@indexInput int
AS
BEGIN
Declare @index bigint, @intRowCount1 int, @intRowCount2 int,@intRowCount3 int, @currentDate Date, @initialTime Time, @currentTime Time;
Declare @initialDate Date, @callDuration int, @calledParty bigint;
set @index=@indexInput;
set @intRowCount1='10';
set @intRowCount2='356';
set @intRowCount3=Rand()*15;
set @initialDate='2012/01/01';
set @initialTime='07:00';
set @currentTime=@initialTime;
set @currentDate=@initialDate;
--Deleting the data in the table
truncate table CDR;
While @intRowCount1 >=1 --For index
begin
declare @subscriberType float=Rand();
--if(@subscriberType<='0.76')
--begin
while @intRowCount2 >=1 --For Date
begin
set @currentDate=DATEADD(DAY, -1, @currentDate);
while @intRowCount3 >=1 -- For Time
begin
set @currentTime=DATEADD(Minute, Rand()*150, @currentTime);
set @callDuration=RAND()*30;
if(@callDuration>='10')
begin
set @callDuration=@callDuration*30+rand()*10;
end
if(Rand()>'0.7')
begin
if(@index<'900000')
set @calledParty=@index+Cast(rand()*1500 as int);
else
set @calledParty=@index-Cast(rand()*1500 as int);
end
else
set @calledParty=Cast(rand()*1000000 as int);
--insert into CDR (MSISDN, Call_Partner, Call_Date, Call_Time, Call_Duration, Location1, Location2)
insert into CDR (MSISDN, Call_Partner, Call_Date, Call_Time, Call_Duration) --, Call_Partner, Call_Date, Call_Time, Call_Duration, Location1, Location2)
Values(
(select dbo.MCI_Subscriber.MSISDN from MCI_Subscriber where ID=@index), --MSISDN
(select dbo.MCI_Subscriber.MSISDN from MCI_Subscriber where ID=@index + @calledParty),
(@currentDate),
(@currentTime),
(@callDuration)
)
set @intRowCount3=@intRowCount3-'1';
end
set @currentTime=@initialTime;
set @intRowCount3=Rand()*15;
set @intRowCount2=@intRowCount2-'1';
end
--end
--else
-- begin
-- print 'Price';
-- end
set @intRowCount2='356';
set @index=@index+1;
set @intRowCount1=@intRowCount1-'1';
set @initialDate='2012/01/01';
print @index;
end
END
وبرای تولید داده تصادفی برای جدول CDR است که دارای فیلدهای موجود در تصویر می باشد.حال می خواهم این store را کاملتر کنم بدین صورت که به ازای هر رکورد مقدار msisn را بگیرد و با توجه به سه رقم اول شماره موبایل استان را معلوم کند مثلا اگر پیش شماره 912 باشد کد استان تهران را از جدول region استخراج کند و در فیلد location1 ذخیره کند و سپس با توجه به استان انتخاب شده به صورت random یکی از شهرهای آن استان را انتخاب کند و سپس کد شهر را در فیلد location2 در جدول cdr قرار دهد
با تشکر109401109402109403