Jeff Moden - Friday, October 20, 2017 7:47 PM
Now this has some interesting stuff going on... You definitely took a more measured approach than I did.
I just picked a date close to middle on the Calendar table, added two "CHECKSUM(NEWID()) % 999999" and simply added or subtracted 9's until it produced legitimate looking ranges.
This... "beg_dt = RAND(CHECKSUM(NEWID()))*@Days+@LoDT " ... This took me a few minutes...I don't ever use RAND() and either didn't know or completely forgot that generates a float <= 1.
For a second I thought you were using voodoo to constrain the output range... I'll have to spend some time using it to see if I like it as much as the % method (thank you for that one too BTW)
Normally if I need "believable" test data I usually do something like this...SELECT TOP 1000
ROW_NUMBER() OVER (ORDER BY c.object_id),
DATEADD(DAY, ld.low_day, '20100101'),
DATEADD(DAY, hd.high_day, '20100101')
FROM
sys.columns c --< this is a lie... IRL it would be a tally...
CROSS APPLY ( VALUES (ABS(CHECKSUM(NEWID())) % 1460) ) ld (low_day) -- 0-4 years
CROSS APPLY ( VALUES (ABS(CHECKSUM(NEWID())) % (1825-ld.low_day) ) ) hd (high_day); -- low-day-5 years
You don't have to sell me on the direct date math or the INT math... there have been a few occasions that the INT math had me feeling like a 4 yr old at a magic show.
Sadly, for whatever reason, they aren't solutions that usually hit me right off the bat.
While on the topic of cool tricks, In the other test harness... I noticed you have a CHECKPOINT...
It makes me suspect that you're grabbing test results from the transaction logs... If so, what's your verdict?
I've been kicking around the idea of using extended events to capture test results, hopefully with less "observer effect" than plan capture & SET STATISTICS IO,TIME ON;
https://docs.microsoft.com/en-us/sql/relational-databases/extended-events/quick-start-extended-events-in-sql-server
Once again, thank you!