Category: Blog

  • Cleaning Up Azure MS Defender Billing

    I have a few Azure subscriptions, which are fairly small and not used that often. Mainly I do some SQL Server or Azure SQL experimentation. Sometimes I might create another resource, but I try to not waste resources and disable them quickly (or drop them) when I’m done.

    However.

    I hadn’t done much in the last couple of months on Azure. For some reason, I decided to check my bill. What I found was that there were charges for $35-ish/month. This is within my free credit limit as an MVP, but that seemed high. I have a few serverless dbs and some storage, but I was expecting more of a $15 charge.

    I decided to investigate. I started with the Billing section, where I saw that Microsoft Defender was swamping the charges in my bill. I don’t remember enabling this, and typically skip this stuff since I work with test data and nothing sensitive.

    2026-10_0159

    As you can see, the Defender items are charged, but not linked to a resource?

    WTF? How do I debug this? I have a small subscription, maybe a few dozen resources. Imagine you had a larger estate? I decided to ask Copilot. I get this result:

    2026-10_0146

    OK, environment settings, let’s check the items under here.

    2026-10_0147

    Now, where is this enabled? I checked the Defender properties for the subscription.

    2026-10_0148

    I went into the various Azure SQL databases, clicked the Security section for Defender and I keep seeing nothing enabled.

    2026-10_0160

    I’m ready to open a case, and waste the days and then multiple contacts trying to work through this with some customer service person in another time zone, who reads docs.

    Digging further, I keep clicking around, Copilot being of no use here. I eventually start clicking in every resource, and I get to the logical server for my Azure SQL Databases. Here’s where I see it, at the server-level.

    2026-10_0154

    I don’t think I turned this on, but perhaps I tested something.

    In any case, I click settings and then disable Defender.

    2026-10_0155

    I’m less concerned that this got turned on, because I might have done that. I would love some auditing of actions to determine this, as I could see someone else in my team (if my team were bigger than me and the 3 dogs) trying this out. I’d want to know who to talk to about changing settings.

    More, I’m annoyed that the bill doesn’t link to resource settings, or that this being enabled at the logical server level isn’t reflected and noted at the database level.

    This was a 45 minute investigation that should have taken 3, so a word of warning to you Azure users. Be careful what you enable, and when you have billing issues, check the resource group and logical servers, in addition to your databases.

  • Car Update October 2026

    This month I want to look at a few of the things I’ve seen posted about cars during the last month. These are a few headlines, as well as some questions I’ve seen on Quora around EVs. Lots of people still worry about the cost and time for charging, so I wanted to add some notes based on my experiences.

    I don’t think EVs are good for everyone, and for most people, this is likely a bit of a calculation that you have to make for your situation.

    UPDATE: I had the Escape cost at $0.81. It’s $0.081.

    Charging Costs

    My cost of power is (usually) $0.14/kWh. There can be a higher charge if I pull power between 4p and 8p, but I can avoid that with scheduled charging. You have to input your own power cost for calculations, which can vary dramatically around the world.

    My Tesla used to use around 260Wh/mi over the long term (75k miles). For the Lucid Gravity, I tend to use more like 285Wh/mi. Those are strange numbers, but if I convert those to a per-mile cost, I get something like:

    • 2021 Tesla MY – $0.036 / mi
    • 2026 Lucid Gravity – $0.04/mi

    These can be compared to my other cars. For comparison, I’ll use my older cars, with a few stats.

    • 2012 BMW X5 – 23mpg
    • 2021 Ford Escape Hybrid – 48mpg
    • 2022 RAM 3500 – 12mpg
    • Gas in the Denver – avg about $3.90 today
    • Diesel in Denver – avg about $5.40

    If I use those numbers, I get calculations that look like this:

    • Tesla MY – $0.036 / mi
    • Lucid Gravity – $0.04/mi
    • 2012 BMW X5 – $0.17/mi
    • 2021 Ford Escape Hybrid – $0.08
    • 2022 RAM 3500 – $0.45

    Clearly the truck is the worst, but a gas SUV which is about the same size as the Tesla, is 5x more expensive to run. The Lucid is larger, and it’s 4x more expensive. Even the hybrid is 2x+ more than the EV.

    There are also the maintenance costs, which are higher, but the quicker tire wear from the EVs offsets some of this for regular maintenance. For longer term stuff, gas cars cost more to maintain.

    What does this mean? I tend to drive in the 12k-15k a year range. At 15k, this is:

    • Tesla MY – $546
    • Lucid Gravity – $600
    • 2012 BMW X5 – $2.550
    • 2021 Ford Escape Hybrid – $1,220
    • 2022 RAM 3500 – $6.750

    The truck tends to run just a few thousand miles, but those are pretty good costs. My charging station cost me $750 installed, which is slightly above the savings from the hybrid. Across 2 years, it’s not close.

    However, if you spend more on power, or your charging station costs more, or you charge at expensive public chargers (Denver Superchargers can be $0.50-0.60), then the savings go away.

    Of course, if you can charge at home, you have lots of time savings as well over the year.

    Charging Time

    What about time? There are plenty of horror stories where people say it took an hour or more to charge. That’s a common concern, as the 0-100 time for a large battery, say 80-100kWh can be high.

    I charge at home, and in 5+ years of owning EVs, I have probably charged 30 times away from home. That’s about 6 times a year. I think the longest I charged was about 45 minutes while eating dinner, but we didn’t need to charge that long.

    Almost all of my charges were while traveling away from home and staying overnight. Most of those sessions were 15-20 minutes. The EVs calculate how much charge you need to get to your destination, which isn’t something most of us are used to with gas/diesel cars. We think in terms of miles.

    For me, 99.9% of the time, I plug in at night (10s) and unplug the next day (10s) and that’s it. Almost never do I exceed a 200mi a day drive. If I do, I might or might not charge. If I’m going 300 mi, which I have done, I would likely charge somewhere along the way for 10 minutes, which is about what a gas stop is with a fill up, bathroom break, purchase a coffee.

    Overnight, whether I’m at 10% of 60%, the car is charged by 7am. I typically set my charger at 34A and start at 10p. Most of the time it’s a 2-3 hour charge if I’ve been driving around.

    Plenty of people worry about taking a long trip. If you do that a lot, then you have to make a calculation of how much extra time you might need. For lots of people this is maybe an hour or two on a long trip, like 1,000 miles.

    How often do you do that? Almost never for most of us. If I were pressed for time on a long trip, say an 8 hour drive to Omaha (600 miles), I’d likely rent a car. Heck, I’ve done that in the past to not wear my car and tires. Otherwise, I’d stop and charge at a few places. The EVs might stop you with 50% to charge or 20% to charge, depending on where chargers are, and they calculate a minimum charge time, so you are often only stopping for 15 minutes.

    The reality in my experience, and in a few friends that have purchased EVs is that the “long trip” isn’t really a common occurrence or issue. Think ahead and make the decision that makes sense.

    Of course, I have a friend in an apartment, no charging available. He sometimes has run an extension cord at 110V to add 4-5mi overnight to his car, but he tends to just use public chargers a few times a week, letting the car charge while he shops or eats nearby.

    If you drive a lot, and you have time constraints, charging might be an issue. That’s not most people.

    Is It Worth Buying an EV?

    To me, with no real cheap EVs in the US, I think it’s worth exploring if you want a new or used car at the EV price points. It’s not likely worth it to change your existing car if you’re happy with it.

  • Experimenting with CHOOSE: #SQLNewBlogger

    I was looking over the CHOOSE() function while editing an article at SQL Server Central. I realized there isn’t a documentation note on how many parameters can be included. I decided to test.

    This post looks at the tests and results.

    Tl;dr It appears 3925 is the most arguments.

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

    Building a Script

    Since I want to know where things fail, I decided to make a short T-SQL script that tests increasing numbers of parameters. This script builds a dynamic CHOOSE() select using a number of parameters and then loops for a set number of times, adding 1 parameter each time.

    SET NOCOUNT ON; DECLARE @MaxValues int = 5150; -- largest number of CHOOSE value arguments DECLARE @n int = 300; -- current number of value arguments DECLARE @i int; DECLARE @idx int; DECLARE @args nvarchar(max); DECLARE @sql nvarchar(max); WHILE @n <= @MaxValues BEGIN -- Build value list: 'Value 1', 'Value 2', ... 'Value n' SET @args = N''; SET @i = 1; WHILE @i <= @n BEGIN SET @args += CASE WHEN @i > 1 THEN N', ' ELSE N'' END + N'N''V' + CAST(@i AS nvarchar(10)) + N''''; SET @i += 1; END; -- Random index in 1..n (CHOOSE is 1-based; out of range returns NULL) SET @idx = ABS(CHECKSUM(NEWID())) % @n + 1; SET @sql = N'SELECT ' + CAST(@n AS nvarchar(10)) + N' AS ArgCount, ' + CAST(@idx AS nvarchar(10)) + N' AS PickedIndex, ' + N'CHOOSE(' + CAST(@idx AS nvarchar(10)) + N', ' + @args + N') AS Result;'; PRINT @sql; -- show the generated statement EXEC sys.sp_executesql @sql; -- run it SET @n += 1; END;


    This returns the command run. For the first 2 values of n, setting @n to 1 and @max to 2, I get this:

    SELECT 1 AS ArgCount, 1 AS PickedIndex, CHOOSE(1, N'V1') AS Result;
    SELECT 2 AS ArgCount, 1 AS PickedIndex, CHOOSE(1, N'V1', N'V2') AS Result;

    This let me test different values. I tried various values and eventually got this error:

    2026-09_0159

    I tried this a few different times, disconnecting and reconnecting and it seemed that I could get the number of parameters up to 3925. It failed sometimes at 3924 and sometimes at 3925.

    I’ve submitted a PR to add the max number to the docs, but it appears CHOOSE() works at a level that would cover lots of items. I see this as a small syntactic sugar add, and if I really needed to index 1000 entries, a join with a reference table would be a better choice.

    SQL New Blogger

    This script took a few minutes to write, but the testing took about 45 minutes. I was running this in the background with different values. 1..256, 255..1024, etc. I noticed that SSMS responded slower, so I started jumping to small ranges at large values to find the error.

    This post took me about 20 minutes to put together after the testing, which included the PR for Microsoft. This is an easy way to show that you can examine possibilities and find the limits of your code. That helps us decide how scalable or robust our solutions are.

    You could write this post and impress an interviewer. Choose your own T-SQL function and run an experiment.

  • A Fun Prize at the PASS Data Community Summit

    I had a briefing for the 2026 PASS Data Community Summit, which is just a couple of weeks away. Amongst a bunch of admin type stuff, there was a slide with a picture of the Redgate Software prize at our booth.

    It’s a Lego Concorde model. That is very cool.

    2026-10_0144

    If you’re attending the Summit, swing by and enter for your chance to win. It’s a pricey (to me) set, though I might have to get one and put a shelf behind my desk with it, and a few other things I need to get on display.