I have a temporary table with the rate and duration in my database:
rate | Period ----- + -------- 3 | Week 1 Month 2 Month 1 Week 3 || Year 1 | Mon 1 Month 1 Month 1 Month 1 Month 1 Month 6 | Year 2 | Month
I need to generate random dates for 2014. For example, there should be 6 random dates for '6 years' 2014 year. There should be a random date for 1 week 2014 in each week. Can anyone help me?
So, this is my work, but the dates are not nearly perfect, maybe anyone can get an error? Generate GenerateTat (@ Date from date, @ Rate Int, Period Navarrek (50)) Start @ Almost Table (Item Date) DECLARE @i int, @j Integer, @d Integer @date date This declaration (@Pyiod as 'Y%') set start @ I = 0 while (@i & LT; @Rate) SET @date = DATEADD (day, dbo.Amount (start 0364) ), @date_from) If @date (select * from LIST *) @LIST values (@date) set @ i = @ I (@PiodEd like 'm%') start start +1 end END Start putting in ii = 1 WHILE (@ and & l T; = 12) BEGIN SET @ j = 0 SET @ d = matter @ when 2 am to 28 when 4 then 30 when 6 then 30 when 9 and 30 when 11 and 30 or so 31 end (@ j & lt; @Rate) BEGIN SETI @ date = DATEADD (day, dbo.Amount (0, @ d-1), @date_from) If @date not (choose from LIST * @) @LIST start setting values (@date) @ j = J + 1 END END set @date_from = DATEADD (month, 1, @date_from) set @ i = @ I +1 end END (@ period% W @ 'like) BEGIN SET @i = 1 WHILE (@ and & lt ; = 52) BEGIN SET @ j = 0 WHILE (@JWLL; @Rate) Set start @date = DATEADD (day, dbo.Amount (0,6), @date_from) @date (choose from @LIST *) @LIST values (@date) set to start @ j = J + 1 END END set @date_from = DATEADD (week, 1, @date_from) Set @ i = @ i + 1 END END Return end date Function amount (@AmountMin boat, @AmountMax boat) declared as @Amount as the start boat float = (select new_rand RandomNumbers) * (@ AmountMax- @ AmountMin) + @AmountMin see returns @Amount end GO RandomNumbers cast selected as the user (rand (eventually (NEWID ())) * 1000 INT) Visit new_rand in
To get 6 different dates in the year 2014, you can try something like below -
announcement @ counter INT DECLARE @MaxDateInterval INT DECLARE @ Tapdet on DECLARE @ Noafdet INT DECLARE @ResultDatesForYr table (TmpDate DATE) set @ counter = 0 sET @ Noafdet = 6 sET @TmpDate = '2014-01-01' sET @MaxDateInterval = FLOOR ((365 - @ Noafdet) / @ Noafdet) WHILE (@ Counter & lt; @ Nofdet) Start SELECT @TMPDate = DATEADD (DAY, (SELECT (1 + FLOOR (@MaxDateInterval * RAND ()), to include @TMPDate in @ ResultDatesForYr (TmpDate) values (@TpmDate) SET @Counter = @Counter select from +1 and * fROM @ result dots: en: Forer
you can write functions that will not accept the necessary and year to date
No comments:
Post a Comment