Author: way0utwest

  • Finding the Last Last Name in SQL: #SQLNewBlogger

    I wrote a piece on the new SUBSTRING in SQL Server 2025 and got asked a question. How do we get the last last name, such as only getting “Paolino” from “Miguel Angel Paolino”. This post will show how you can easily do this.

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

    The Scenario

    I have a set of names, like those in the Northwind.dbo.Customers table. I want to find the last names only, perhaps for a mailing, or maybe for a search box. I have names like these:

    2025-11_0155

    Notice line 80 above. There are three names here. In the US, we might consider this as a first, middle, and last names. In Spain, however, this might be a first name and two surnames. If I only wanted the last last name (Paolino), how can I get that?

    One of the cool things about working with strings is that we can look at them a few ways, and we have a great T-SQL function that can help: REVERSE(). The last last name is really the first name in a reversed string.

    Backwards, but we can fix that.

    Let me build up a query. First, I’ll get the ContactName and then the First Name. I’ll use the Charindex to find a space and then assume everything before the space is the first name. That gives me this code:

    SELECT
            ContactName,
            SUBSTRING(ContactName, 1, CHARINDEX(' ', ContactName)) AS ContactFirstName
    FROM dbo.Customers;

    And these results. Notice I have the first names. This isn’t perfect, but it’s often works.

    2025-11_0157

    Now, let’s add the string reversed.

    SELECT
            ContactName,
            SUBSTRING(ContactName, 1, CHARINDEX(' ', ContactName)) AS ContactFirstName,
            REVERSE(ContactName) AS ReversedName
    FROM dbo.Customers;

    The results are interesting. Look at lines 79 and 80. The first name is the first word before a space. For the last name, it’s the first word before a space, but reversed. The first part of 79 is shpesoJ and the first part of 80 is oniloaP.

    So let’s repeat our substring on the reversed string. Here’s new code:

    SELECT
            ContactName,
            SUBSTRING(ContactName, 1, CHARINDEX(' ', ContactName)) AS ContactFirstName,
            SUBSTRING(REVERSE(ContactName), 1, CHARINDEX(' ', REVERSE(ContactName))) AS ReversedLastName
    FROM dbo.Customers;

    And look at the results. now my third column is the last name, just backwards.

    2025-11_0159

    Now we can wrap that last column in another REVERSE() and we get the results we want.

    2025-11_0160

    SQL New Blogger

    This is a common type of task, and one that you might be asked in an interview, or as a part of a spec. This post only took about 10 minutes to write, with code, and if this were on your blog, I bet an interviewer would ask you how to do this.

    Try to influence the interview and write your own post. Do some testing on performance as well, explore how to work with T-SQL to become better at it and showcase this to your next hiring manager.

  • SQL Server 2025 GAs Today

    If you aren’t watching the Ignite keynotes today, then you might have missed the announcement that SQL Server 2025 officially releases today. The main SQL Server page gives you a place to get some marketing info, while the docs should change to remove “preview” today.

    I’ll have some thoughts later in the week, but this has been a low key release for me. While I’ve been hearing about different features, both publicly and under my MVP NDA, there hasn’t seemed to be a lot of people excited about the release.

    That makes some sense as the product is very mature, and most of us use the core features, which sometimes get improvements in new versions, and sometimes regressions.

    In any case, as I look through the What’s New, there is a lot of stuff changing, and a lot of additions. I always like the T-SQL language changes, and with so many people using JSON these days, having more functions to work with these strings is important. Regex is meh for me, but fuzzy string matching is interesting.

    SSMS v22 also goes GA today, and I hope it’s more stable than the preview has been. I’ve tried the GitHub Copilot in here, and I keep seeing freezes in the app. However, I also think this is a feature that will get a lot of data professionals experimenting with AI. Of course, if you have SQL Prompt, I’d suggest you try it there first.

    The big thing that I’d have appreciated in a lot of jobs, and I think a number of customers will like is a Standard Edition version of Developer Edition. That prevents mistakes where devs read about something on SQL Server Central or elsewhere and then implement it in dev, without realizing it won’t work in their production Standard Edition version.

    I don’t know how excited many of you are to use this version, but it’s the latest one and starts the clock on 10 years of support for security fixes. We’ve had a few lately, so at this point, if I were upgrading an older instance, SQL Server 2025 is where I’d go. Especially now that Standard Edition can run with 256GB of RAM. That alone might get me to upgrade some older SE instances.

  • The Roundup for T-SQL Tuesday #192

    Last week I asked you to write about SQL Server 2025 and what things you might be looking forward to in the new version.

    First, as usual, is Rob Farley. He has an advantage, being in Australia, so his day starts earlier than most. His post this month is on string matching, and he is sad that Master Data Services is leaving in 2025. I’m not sure many people used it, but I also don’t know it was worth removing. However, there are new functions for fuzzy string matching, which are some options for helping with data quality.

    Chad write about something I’ve been asking Microsoft about for years. We are finally getting a Standard Edition version of Developer Edition. Chad writes in more detail about this and how to install it.

    Deborah writes about two features: optimized locking and ADR. Performance is always on the mind of most people who work with databases, and these two features should help improve performance.

    Andy has written on a few AI things in SQL Server 2025, so I expected more. However, I got an AG enhancement I wasn’t aware of that is coming.

    Rob in New Zealand writes about security changes in SQL Server 2025, but also notes that the Copilot Integration in SSMS 22 is really what he is looking forward to working with.

    My own post was on the backup changes, letting me backup on all replicas.

    Louis writes about regex. I was expecting more people to choose this, but glad Louis did.

    Glad to see a few people participating. If I missed you, please send me a note with the link.

  • Don’t Create Workslop

    I remember a time before email. Some of my first jobs were mostly based on paper being moved from person to person. I’m sure some of you remember these envelopes being used to communicate between individuals in an organization. I used those to send and get memorandums from others before we implemented email. Fortunately, our email implementation (cc:Mail) came soon after I started working in corporations.

    Initially, people treated email much like paper mail inside organizations. However, over time, people started to treat email differently. It was easy to send an email around other work, so people started to send more messages than they ever would have with paper. They started to dash off notes quickly, sometimes too quickly, as an email might be followed by another email that includes a “I forgot this”. As instant messaging grew, we saw similar patterns where people were quick to send messages, regardless of whether they were important, well-thought-out, or even necessary.

    As AI becomes more widely used in the workplace, there’s a similar tendency. People are quick to use AI to generate something and send it to others, often without due diligence on their part to ensure the work is at the quality level the other person expects. Some workers don’t double-check what they received from the GenAI tool, and it may not be complete enough to actually satisfy the requirements they were given. Maybe even worse, the result might not be targeted at the problem that was supposed to be solved.

    I ran across an article on workslop, which is defined as AI-generated work that masquerades as good work. Instead of actually being what the organization needs, it’s sloppy, it’s low quality, or it misses the mark.

    To be fair, I don’t think this is an AI issue. I have worked with plenty of people who produced low-quality output that wasn’t good enough for me to use. I’ve seen plenty of people not really try to produce quality results and do a poor job of completing the tasks they were assigned. With AI, they can do it quicker, which can be a problem, especially if they are producing things other employees depend on or need. The result might be some people be pushing their work onto others who have to spend time fixing (or completing) the copy/pasted GenAI results, taking away from the time others might spend on more important tasks.

    In the technical world, we saw that in the 90s with VB6, where lots of technical and nontechnical people produced code quickly for an application that worked initially, but didn’t perform well, couldn’t be scaled to others, and wasn’t stable enough to run every day. Sometimes not stable enough for an hour. I suspect we’ll see a lot of AI-generated code that repeats this pattern. Not because the AI can’t generate good code, but the people using it won’t know how to ask for good code, with instructions about the types of code that create robust applications. They also won’t know (or won’t bother) to check the code for quality.

    My guess is that the GenAI adaptation to lots of work will result in a lot of things produced, but at a lower quality than we might want. We’ll also see this phenomenon create inefficiencies as other workers have to return or repeat work. Fortunately, there is a lot of room for inefficiency in many organizations, so they can likely continue to function.

    Those that learn to use GenAI well to produce higher quality work will do so faster and stand out from their peers. Of course, a big part of standing out is also developing strong soft skills and advocating for your accomplishments. Without that, you might find those who produce workslop, but talk about it well to others will stand out from you.

    Steve Jones

    Listen to the podcast at Libsyn, Spotify, or iTunes.

    Note, podcasts are only available for a limited time online.