T-SQL Tuesday #143 – Random Fun

This month’s T-SQL Tuesday is hosted by John McCormack, who asked participants to blog about Short Code Examples.

A few years ago, I wrote a similar blog about T-SQL Tools that I could not live without. Those were my snippets files, which I maintain in Google Drive. Not much has changed since I’d spent the last 4 years working for SentryOne, but I still maintain the entire toolset and did use it periodically.

For today’s, I’m going to dive into my 1_Scripts.sql file and share some of my favorites all involving “random” values!

Random Fun

First, there are times where you need multiple random numbers. Simply using multiple iterations of RAND() in a single statement won’t cut it, as you need to vary the seed. So I keep this snippet handy for when I need a bunch of random values in a single statement:

/* Random Number between 0-99 */

Wait For Me Randomly

During my time at SentryOne, I found that I had to create mock workload on a regular basis. I wanted to introduce some unpredictability to make demos more interesting, so wrote this chunk of code to introduce random WAITFOR DELAY intervals.

/* Shell Agent Job with randomized runtime */

    @DelayMin INT = 5,
    @DelayLength CHAR(8) = '00:00:00'; -- hh:mm:ss
    -- Create randomized 5-15 MINUTE WAITFOR DELAY
   @DelayLength = '00:'
   + RIGHT('0' + CAST((@DelayMin + CAST((RAND(CAST(NEWID() AS VARBINARY)) * 100) AS INT) % 15) AS VARCHAR(2)), 2)
   + ':00';
   -- Create randomized 5-15 SECOND WAITFOR DELAY
   --@DelayLength = '00:00:'
   --+ RIGHT('0' + CAST((@DelayMin + CAST((RAND(CAST(NEWID() AS VARBINARY)) * 100) AS INT) % 15) AS VARCHAR(2)), 2)

SELECT @DelayLength AS '@DelayLength';

PRINT 'START - Do Something';


PRINT 'END - All Done With Something';

For My Final Trick, Random Strings

In much of my AutoDealershipDemo database, I have random strings for various things, so needed code to do that. I’m using a Tally Table approach, that then combines CHAR() with modulus operators to only general alpha-numeric values. But this can easily be adapted for other values available in CHAR().

; WITH Ten_CTE (N) AS (
), Thousand_CTE (N) AS (
), Tally_CTE (N) AS (
   -- This provides the "base" CTE and limits the number of rows right up front
   -- for both a performance gain and prevention of accidental "overruns"
   FROM Thousand_CTE
   -- CROSS APPLY Thousand_CTE t2 -- UNCOMMENT IF YOU WANT 1,000,000 results instead of 1,000
   -- Increase concat below to increase length of string
   CHAR(ABS(CHECKSUM(NEWID())) % 26 + 97)
   + CHAR(ABS(CHECKSUM(NEWID())) % 26 + 97)
   + CHAR(ABS(CHECKSUM(NEWID())) % 26 + 97)
   + CHAR(ABS(CHECKSUM(NEWID())) % 26 + 97)
   + CHAR(ABS(CHECKSUM(NEWID())) % 26 + 97)
   + CHAR(ABS(CHECKSUM(NEWID())) % 26 + 97)
   AS RandomString

Hope you’ve enjoyed reading. These will most likely not be useful to the vast majority of you. But if you do ever have to write some mock workload, demo scripts, etc., then hopefully you’ll remember this blog post and make use of the above!


Standing Desk: V3

It seems crazy to me that it’s been FIVE YEARS since I last blogged about my Standing Desk setup, and boy a LOT has changed!! During those years, I moved several times, but my Ikea standing desk stuck with me.

Out With The Old

This month marks a big career change for me so I decided it was finally time to retire my Ikea setup. It is sturdy and solid enough but its biggest drawback is that it is not really convertible between sitting & standing. Technically you could change it up with the pegs and trestle legs, but that’s very impractical given how much heavy hardware “permanently” lives on the desk to begin with.

My old standing desk built from Ikea parts

So What Did You Want?

My new office space is a smaller converted attic room, which presented some limiting factors – the primary being desk width because of where I can place a standing desk with my sloped ceilings. This limited to me to setups around 40 inches wide. Because of another storage dresser, I had to overlap my window but I don’t mind. I also wanted to treat myself to a real wood desktop vs the cheap corrugated Ikea top I’ve had since the beginning.

What’d You Wind Up Buying?

After a ton of research, I wound up selecting Uplift. Went with a walnut butcher block top, C-frame, and decided to be a bit different with their “industrial” finish. I enjoyed having a monitor shelf, so added that option as well. The biggest drawback to my old setup was that I lost desktop space to my keyboard & mouse, so I also opted for an under-desk keyboard tray.

Uplift desk pre-assembly photo
C-frame almost done!
Had to stop and actually do some work, so used a TV tray! 😀
All stood up!

And here’s the final product! I kept my Vivo laptop stand, added some cheap LED under-cabinet kitchen lighting that we had leftover from our last place, and picked up a set of Cyber Acoustics CA-SP34BT 2.1 speakers for music.

Seated position w. my Steelcase Gesture
Standing position

What’s That Underneath Your Desk?

But it’s what’s underneath my desk that’s noteworthy. I’d been using an Ergodriven Topo mat for years and think it’s great. But I wanted something more. A few years ago, I’d learned of under-desk elipticals for sitting desks and began to wonder if there were now specialized treadmills that’d fit under a standing desk.

A quick bit of research yielded a number of results that seemed like fairly cheap Chinese treadmills. If I wanted solid quality, I’d be looking at spending at least $800 if not more. One key detail about an under-desk treadmill is that its not meant for hardcore running. I also wanted something “portable” enough to move out of the way, which is why I did not look for a traditional running treadmill.

Uplift + GoYouth under-desk treadmill

In the end, I opted to go with a lower-end treadmill. I’m optimistic that I can get into a habit of using it regularly, especially while on webcasts or doing lesser intensive tasks like reading, e-mail “chores,” etc. And if it winds up like other home exercise equipment often does (as a clothes hanger), then I won’t feel as bad if I had burned cash for a higher end model.

Was It Worth It?

My setup has been operational for a few days now and I’m pleased to share that I’ve already gotten good use out of the treadmill. Ran it for during a few meetings in my last workweek, and I after a while, I didn’t notice the treadmill at all. I’m only walking between 0.8MPH and 1.4MPH at this point, to get used to walking while doing stuff. Don’t expect to get much faster than that but I’m okay with that. As long as this thing keeps me moving for an extended period of time AND I can ingrain its use as a daily habit, I’ll call it a win.

End of Another Chapter


Today is my last day with SentryOne. And burnout has been kicking my ass HARD. But I've mostly defeated it and am looking forward to what's coming next.

A Retrospective

Just over four years ago, I had the fortune to join SentryOne. And today, that journey comes to a close. I am forever grateful for this fantastic chapter of my career and wanted to blog a bit about it (mostly for me, but if you're here, hope you enjoy the story too).

Never Dreamed I'd Be In Sales... and LIKE IT

When I was a very young child, I was asked what I wanted to be when I grew up and said a "salesman." My father was in sales, which is most likely why I gave such an answer. But then I discovered video games, which drove me to computer science, and while eventually lead to databases and SQL Server. In 2013, I started speaking and found that I was good at it but really loved it. Through speaking and events, I met many wonderful people including Scott Fallen, who recruited me into SentryOne, as a Solutions Engineer (aka a pre-sales engineer). When I started as an SE, I never knew such a role even existed. And in my first few months, I thought I made the worst mistake of my life! At that point, I knew how to present, teach, train, and consult. But there's a different nuance with a pre-sales role. You do all of those things yet you don't do any of them fully. Eventually it clicked in my brain, that I needed to not teach and explain, but rather to showcase, highlight, and most importantly, listen. Once I figured that out, I grew as a pre-sales engineer and found that it was one of the most rewarding roles I've ever had. It's true... I came to love pre-sales.

Change Is Inevitable - 2020

We all know how everything changed in March of 2020. What followed for me through the remainder of 2020, was a great deal of personal, community, and professional changes.


Am not going to blog details publicly, but 2020 brought about many lows but some very wonderful highs too. And at the end of 2020, I moved to Boston to start a new chapter of my life there.


In the course of my career, I'd been a part of SEVEN acquisitions and/or mergers. I dodged two more, as those were coincidentally announced after I had given notice but before I'd left the respective company. The craziest one was when Lehman Brothers shuttered. My company was a wholy-owned subsidiary of Lehman Brothers. I distinctly remember our CEO calling an all-hands Monday morning, telling us straight up that we had two weeks of money to pay everyone, and that he'd be spending every waking minute trying to find us a new home. He was successful and we had new ownership four days later. Another job of mine seemed like a fantastic home for me. That company was a small start-up that had just been acquired. I was the first hire under the new parent company. Unfortunately, conflicts arose with another key employee and the environment became toxic, so I left after seven months. That worked out for the best because the next year, the parent company terminated almost everyone who had been acquired! In October 2019, SentryOne was acquired, making it acquisition number eight for my career journey. It's frankly annoying how I frequently find myself at companies that get acquired! In some acquisitions, nothing really changed except the company name, e-mail addresses, and HR stuff. But other cases, well, a hell of lot changes. And not all change is for the better either.


As a speaker, I continued to be extremely active as we shifted fully online. I wound up presenting MORE in 2020 after March, than in all of 2019, thanks to everything being virtual. As a user group leader, I embraced the virtual path and started hosting meetings twice a month. But when the end of the year rolled around, I came to a powerful realization - I was BURNED OUT HARD.

Fighting Burnout - 2021

2021 rolled on in, bringing about many new changes. Deborah and I bought a new place together in Boston. As awesome as that is, moving and "new home to-do's" are still a significant stressor. And I was still feeling burnout and stressed. The good thing is that I was aware and conscious of it, so tried to mitigate it as best I could. The hardest and easiest mitigation was electing to cut back on my community involvement. I relinquished my leadership role in the Chicago Suburban User Group. I opted to not speak at all during Q1 2021. And I reduced my speaking engagements dramatically the remainder of 2021. Finally I drastically reduced my social media presence and consumption. There were a number of controversies in the community, especially earlier this year, where I opted to remain silent. Frankly, I got to the point where I might only open Twitter once a day or only check DMs and that's it. It's been good for my mental health, but I do miss interacting with #SQLFamily.

What Brings You Joy?

When my first 2021 speaking engagement rolled around, I'll confess that I found myself dreading it. I did not have the energy or the desire to do it. I wondered if this was finally the sign that I should stop speaking entirely. But a commitment is a commitment and I'm glad I went through with it. I found that when "the lights went on and the curtains opened," I rediscovered the joy of speaking and presenting. I recognized that it was my burnout that made me dread it. But in the end, I did miss it and still loved presenting.

Mourning the Past

Aside from speaking, I did my best to combat my burnout and stress. The summer of 2021 was particularly rough, with a few key setbacks that hampered my attempts to shake off my burnout. But more importantly, I realized that I had been in a cycle of mourning as well, not wanting to accept professional changes. In the end, I stopped resisting, came to terms with the passing of something I loved, and moved on. Once I did, I could finally look forward again and a weight was slowly lifted from my shoulders.

Looking Forward to What's Next

I always say that I believe in "counting one's blessings." And a few weeks ago, one of those blessings came in the form of a new opportunity. As excited as I am, I'm going to wait a bit before I share where I'm going next. I'm doing this because I want to focus the next few weeks not on what's next, but on the now. I'll be taking the next month to fully recharge and eliminate any remaining burnout of 2020/2021. I'm done with burnout bullshit and am eager to move forward again.