Category: Blog

  • RANK() vs DENSE_RANK(): #SQLNewBlogger

    Recently I had a question asked about why someone choose DENSE_RANK() vs RANK(). This was an analyst trying to decide how to produce a report, and I spent a few minutes helping them. This is a great, basic post on how this works and why I’d choose one.

    Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

    The Scenario

    I wrote a question on this topic, and I’ll explain it in more detail. First, the setup. We’ll create a table and add some data.

    CREATE TABLE dbo.BlackFridaySales
    (
        Product NVARCHAR(50) NOT NULL PRIMARY KEY,
        Units   INT          NOT NULL
    );
    
    INSERT INTO dbo.BlackFridaySales (Product, Units)
    VALUES (N'55" TV',          900),
           (N'Air Fryer',       500),
           (N'Noise-Cancel Headphones', 500),
           (N'Robot Vacuum',    300);

    Next, let’s query the table and rank the sales. If we look above, we see that the product were inserted in the sales order, so the TV had the most units and the vacuum the least. We’d expect a ranking like this:

    1. TV
    2. Air Fryer
    3. Noise-Cancel Headphones
    4. Robot Vacuum

    Except, how do we rank the middle 2? Those had the same sales. If you reported this orally to someone, would you rank them as 1, 2, 3, with 2 items at 2? Are they 1, 2, 2, 4? Something else?

    Let’s look at T-SQL.

    Rank

    RANK() will produce the results that work like the placing in a race. If two people tie at second place, third place is lost and the next person gets fourth. Lots of sports work as RANK() does, with a result of 1, 2, 2, 4.

    2026-11_0345

    In this case, we would have to decide somehow which is 2nd and which 3rd, or leave them as 2nd in a report. After all, with 4 items, there are four places to fill.

    DENSE_RANK

    As the name implies, DENSE_RANK() closes of the orders and creates a more “dense” ranking. The results below show the ties, and then start sequencing with the next number, 3. The resultant ranking is 1, 2, 2, 3.

    2026-11_0346

    Less useful for competition, DENSE_RANK is more of a keeping things in a sequential order type of function. This is more useful for things where a discontinuity is a problem. Think sales promotions or other “brackets” of data. For these, we don’t want to skip numbers.

    SQL New Blogger

    I spent a few minutes trying to help someone to solve this, and I mocked a few things up. Taking that mock and then writing around it took me about 10 minutes to clean up some code, and then about 10 minutes to write the post.

    This is an easy way to showcase why you might make a choice, and why/how you might guide an AI. Try putting together a post on how you’re guide and evaluate an AI in a similar scenario. Maybe add some testing around this.

  • Finally! I Can Read Numbers in SSMS

    I was excited to try out the latest release of SSMS, v22.12.1 for this reason:

    2026-11_0333

    Did you notice anything? Here, let me know you what I saw in 22.10, the previous version I was running:

    2026-11_0334

    Same query, but the top one is so much easier to understand.

    In case you didn’t realize it, the top results (blown up), look like this. I now have separators for large numbers.

    2026-11_0335

    This was a change that has been asked for across many years, and it’s now in the product. If you go to Options, and the SQL Server Results to Grid, you’ll see a new Number Formatting section.

    2026-11_0336

    The default for digit grouping (the thousands separator) is none, but I’ve set it to Commas. I can set it to other things, as some cultures use different items. You can see the list below.

    2026-11_0337

    I also have similar options for the decimal separator.

    2026-11_0338

    A fantastic change, and one that all software should support. Use regional settings, and allow users to change things. This makes things much, much easier to read.

  • November 2026 Car Update: MPG Comparisons

    I’ve become an EV guy. I was talking with a friend who was selling his Porsche 911. He asked me if I was interested, and I was, but not really. Between getting down into a car that’s 4” off the ground and dealing with maintenance, I think I’m mostly done.

    As it is, I had to change oil in two vehicles lately, and it’s a PIA. The less maintenance the better, and in 5 years between a Tesla and Lucid, I don’t think about it often, but when I do, I appreciate no maintenance needed.

    I’ve enjoyed driving the cars, but the tech aspects are interesting as well. I see lots of questions and comments (usually uninformed) about EVs online. I try to neutrally answer some, especially on Quora, just giving my experiences. Recently, I found myself drawn to this one: Is it true that charging an electric vehicle at home is like getting 230 miles to a gallon? How can that comparison vary based on where you charge?

    Here are my experiences, using a few vehicles I’ve owned more than a year. I’ll use today’s costs:

  • Prius – $34.57
  • RAM Truck – $42.23
  • BMW X5 – $15.21
  • Tesla – $3.12 (around 140mpg)
  • Lucid $4.33 (around 101mpg)
  • The assumptions here are:

    • Gas $3.60/gal
    • Diesel $5.49/gal
    • Electricity $0.13/Kwh
    • Prius 47mpg
    • RAM $13mpg
    • BMW – 24mpg
    • Tesla 240Wh/mi
    • Lucid 333Wh/mi

    Even a much less efficient Lucid, which is larger than the BMW, is cheaper to operate on a daily basis. I’m also not sure that the EVs eat tires much quicker than the BMW. They certainly do quicker than the Prius or RAM (or Suburban, which is similar to the BMW for fuel), but those have maintenance costs that likely even things out.

    I used some AI for the calculations, but to get the Prius to break even with the Tesla, I’d need gas to be $1.47. For the Lucid, it’s a possible $2.03/gal. For the BMW, gas would need to be $1.04.

    Those are hard costs.

    Those leave out the time costs. If you have to find a charger somewhere, then $0.13 is likely low, and charging takes time. However, if you can charge at home, then there is a significant time savings across a year. It’s 10s a day, a minute (roughly) a week to charge. That’s about an hour a year.

    An ICE car, let’s pick the Prius and 15k miles driving a year, I then spend about 2.3 hours charging. That’s not a lot, but it’s also time driving to/from the station. Plus the temptation to spend on coffee. soda, chips, candy, etc. in a shop.

    To be fair, I still do those things, which is why I don’t really look at time as a factor here. I still stop regularly for coffee or soda (I have a problem, but hey, you have to die of something).

    In the BMW, if I drove it like I do the EVs, then I’d likely spend 4 hours a year fueling, which still isn’t a big deal. Watching the prices, though, especially for the RAM, are a stressful item that is hard to measure. It’s certainly way more stressful to watch the costs spin up than plan charging in an EV.

    This isn’t to say EVs are perfect, but to me, it’s the future. Every time I wish I had a Porsche or other car to drive, I realize that the Lucid gives me a lot of the same straight line performance, and even some of fun handling in curves, in a level of comfort that’s hard to beat. Not that I’d drive on a track, but it’s neat to see. The cost of tires keep me driving a little more conservatively these days.

    If you live in the US, treat an EV like the cloud. When you need a new car, think EV first. Look at options, see how much and how often you drive, consider where you can charge, and then decide. They’re not for everyone yet, but they are amazing. Batteries last a long time, and used EVs are something I’d consider. Heck, if we needed another car for limited drives, I’d be tempted by a used EV. Though to be fair, a spare car should be cheap, and it’s hard to beat a used ICE car for $4k that I might drive 2000 miles a year.

  • Memories of PASS Data Community Summit 2026

    A bit of a photo dump, but a few fun memories for me from the recent PASS Data Community Summit. I arrived late Sunday night, making half of our volleyball practice before flying to Seattle. I guess I technically arrived Monday morning at the hotel around 12:15a.

    Monday was rehearsal. I saw a long line of people waiting as I made my way to the keynote room. People pitched in from Redgate to help, but we need to find a better way to do this in 2027. It was cool to see a bunch of people I knew waiting around. It was also neat to see people interacting together. There was coffee available, which always makes a different.

    2026-11_0311

    I didn’t spend too much time as I’d gone to Ludi’s for breakfast takeout and it was still hot, so I wanted to eat. I can’t recommend that place enough.

    Rehearsal was good. The lights were bright on stage, and not even my hat helped. One of the challenges of speaking, especially when you’re looking down at a monitor with notes, trying to remember where you are in the presentation. Working without a laptop is something I’ve gotten used to, but it was interesting to coach a few others here.

    2026-11_0312

    We got done and wandered around for the day. I had a few people to catch up with, so I wasn’t back until the evening. Here’s part of the crew at the reception. Shirt du jour was a popular one, with the map view. I liked that I didn’t need to do a lot of walking. I was also close enough I could run to my room and be back in less than 10 minutes.

    2026-11_0307

    A few other selfies with friends. I didn’t get enough of these. If you got one with me, send it over.

    2026-11_0315

    2026-11_0314

    2026-11_0313

    Tuesday I had the intro for the Microsoft keynote. I picked this shirt, because I knew I needed to honor Hugo Kornelis, and also remember he’d want us to have fun.

    2026-11_0317

    I grabbed a morning shot from the breakfast session. A little shaky. I suspect I was nervous before the keynote.

    2026-11_0316

    The intro went fine, though my voice cracked. I grabbed this shot, but I suspect I’ll see some great ones from Rodney Kidd soon.

    2026-11_0310

    I left the keynote with tears in my eyes. I couldn’t stop, so headed to my room and a chat with my wife. I also took a few minutes for a workout, which was needed.

    2026-11_0319

    The rest of the day was more practice for me before the welcome reception. I realize I didn’t take many photos. The day was a blur for me.

    Wednesday we had the Redgate keynote. My view backstage, ready to get going.

    2026-11_0320

    The keynote went great. Slightly long, but close. The thing that was the most fun was watching Tom take on his alter ego, Steve the DBA.

    2026-11_0318

    It was a great event and a lot of fun. I was actually happy it was short, though somewhat wish I’d been there Sunday and spent more time with people, as well as had a few less commitments on Monday/Tuesday to spend with people.

    I’m excited for Denver next year, and hope to see lots of you there.