Author: way0utwest

  • STRING_SPLIT Basics–#SQLNewBlogger

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

    I saw a post on using STRING_SPLIT() with cross apply recently, and as I was reading, I realized that I hadn’t adopted this very often in code. Mostly it’s not something I need to deal with, but recently my wife did give me some data and asked to reformat it, and I used STRING_SPLIT(). I thought it was a nice easy problem, so I decided to write about it.

    Conflated Data

    The dataset that she gave me was formatted something like this:

    2021-09-17 15_32_22-string_split_experiemnt.sql - WAY0UTWESTHP_SQL2019.sandbox (WAY0UTWESTHP_way0u (

    What she wanted was a report that provided data more like this:

    2021-09-17 15_37_20-string_split_experiemnt.sql - WAY0UTWESTHP_SQL2019.sandbox (WAY0UTWESTHP_way0u (

    This was more complex in the past, and hard in T-SQL as string manipulation isn’t great. However, STRING_SPLIT makes this easier. Not great, but easier.

    STRING_SPLIT

    While STRING_SPLIT is a function, it is a table-valued function, meaning that it is used as the source for a data set. Rather than being in the SELECT column list, we would use this in the FROM clause as another table. Or anyplace a table can be used.

    The basics of this would be:

    SELECT ss.value
      FROM dbo.ClassSchedule AS cs
       CROSS APPLY STRING_SPLIT(students, ',') AS ss

    Using this code, I would get a list of students.

    2021-10-18 08_58_00-SQLQuery2.sql - ARISTOTLE.sandbox (ARISTOTLE_Steve (70))_ - Microsoft SQL Server

    The STRING_SPLIT returns this single column, value, which is the string passed in split by the separator. I could see this more simply with this code:

    SELECT * 
      FROM STRING_SPLIT('alpha,beta,delta,gamma',',') AS ss

    This returns these items:

    2021-10-18 09_06_24-SQLQuery2.sql - ARISTOTLE.sandbox (ARISTOTLE_Steve (70))_ - Microsoft SQL Server

    A few more examples:

    2021-10-18 09_07_23-SQLQuery2.sql - ARISTOTLE.sandbox (ARISTOTLE_Steve (70))_ - Microsoft SQL Server

    2021-10-18 09_08_21-SQLQuery2.sql - ARISTOTLE.sandbox (ARISTOTLE_Steve (70))_ - Microsoft SQL Server

    The important thing to note here is that this is a simple substring based on the separator, with no other processing. Spaces or any other character outside the separator is left in the result.

    There also is no ordering of the results. While this appears to be in the same order in these simple examples, this is not guaranteed, meaning the ordering of the substrings might not match the original order.

    This is a good way to easily split up data that you have stuffed into a large character field, but it has limitations, so use it carefully.

    SQLNewBlogger

    This post took me about 15 minutes to write after spending 5 minutes setting up some test data. I was using string_split to clean up some data and decided to make a few notes, then built a new table with some strings in it to help me explain how it works.

    A good example of a post you could write, perhaps noting when this was released or comparing this to a way of splitting these strings with a more complex T-SQL query.

  • Growing and Keeping Up

    I keep busy. My wife and I tend to be type-A people, tackling lots of things and keeping very busy. We work hard, and often, a lot. Our spare time in the winter is spent with second jobs, coaching youth volleyball. My kids think that we can be a little unbalanced at times, not taking enough time off or getting away from work. I agree. They are better balanced in life than my wife and I.

    The thing I tell me self is that keeping busy and being driven has helped me have a great life and a great career. It’s also created lots of stress, perhaps more than I should have. I thought about this balance as I was watching I Can’t Keep Up!, Catherine Wilhelmsen’s keynote from Data Saturday Oslo. It’s a great talk and worth your time to watch. She tells you that while you can do anything, or almost anything, that you want, it’s not necessarily easy. You have to work, but you have to find some balance.

    The world of technology has grown at a crazy pace during my life. As I’ve watched the growth of cloud capabilities from vendors, I’ve felt the same things Catherine has. I can’t keep up, I don’t have time to keep up, and everyone likely knows more than me about many things.

    All of those things are mostly true.

    I can’t keep up, I don’t really have time to try, and certainly, there are plenty of people who know more than me about any particular thing. However, I should learn to accept those things, not worry about them.

    It’s easy to get stressed or feel discouraged at your lack of being an expert in your field. There is good advice in the talk, but the thing that I try to remind myself of often is that I know more than last year. I am good at some things, and I continue to improve my skills in some areas. Most importantly, I can prioritize, pick a few things, and then work on those across time, which is enough to help me succeed.

    I have learned to set a few reminders each month and focus at those times on something that I want or need to learn. I also allow myself some free time to improve myself in a general way, without an agenda. I struggle with distractions, but I do try to remind myself to focus when I have time. The key in technology is learn how to learn. Don’t worry about picking the perfect technology or being as efficient as you can. Just learn something and get comfortable with regularly learning about new skills. Even if you choose something you never use later, you are building the skill and habit of learning.

    It’s good to challenge yourself, but be realistic, and more importantly, find balance. If you are starting out in your career, without many external obligations, you may have more time to work on your career, but you also have more to learn. Be patient with yourself and learn to enjoy life outside of your career field, even if you spend lots of hours trying to grow your career skills.

    If you are older, perhaps you pick something related to your work, or perhaps you pick something that interests you. Either way, exercising your brain and gaining new skills, however slight, is helpful.

    Always remember, we work to live, not the other way around.

    Steve Jones

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

  • Daily Coping 18 Oct 2021

    I started to add a daily coping tip to the SQLServerCentral newsletter and to the Community Circle, which is helping me deal with the issues in the world. I’m adding my responses for each day here. All my coping tips are under this tag.

    Today’s tip is to set hopeful but realistic goals for this week.

    It’s a busy week here for me. After coming back from travels, I’ve got a lot of catching up to do at SQLServerCentral. I also have a number of work commitments, with other goals I’d like to accomplish this week in my life.

    What I feel I need to do:

    • get to the gym 4 times
    • go for a hike
    • get to a high school volleyball game
    • spend a few hours mowing the lawn
    • paint a fence post
    • run the weed whacker one last time and trim around the house and empty the gas tank
    • fix the string trimmer head on the weed whacker to cleanly dispense new string
    • cook dinner every night
    • see a movie with my wife on the weekend (first one since 2019)
    • finish painting the bathroom
    • catchup on laundry

    Realistically, this is too much, with 2 presentations to give, a third to record, and a number of other meetings. Likely I’ll need to decide which things are realistic for the week and weekend. I’ll choose:

    • get to the gym 4 times
    • go for a hike
    • get to a high school volleyball game
    • spend a few hours mowing the lawn
    • fix the string trimmer head on the weed whacker to cleanly dispense new
      string
    • see a movie with my wife on the weekend (first one since 2019)

    I’ll probably be able to cook a few nights, I might get to actually trim something or do some painting, I’ll do some laundry. I also know I need some downtime, I want to relax with the guitar, and spend some time with my son.

    We’ll see how I did on Sunday.

  • Daily Coping 15 Oct 2021

    I started to add a daily coping tip to the SQLServerCentral newsletter and to the Community Circle, which is helping me deal with the issues in the world. I’m adding my responses for each day here. All my coping tips are under this tag.

    Today’s tip is to be a realistic optimist. See life as it is, but focus on the good.

    This is something I’m writing while in Belgium, earlier this week. I am optimistic in life, even as the world struggles in different ways with the pandemic. We are still moving through this, with various places and organizations trying to find ways to cope.

    I am at the first live technical conference I’ve been to in nearly two years. The event is following the local guidance in Mechelen in Belgium. Things have changed a bit since I submitted and was accepted to the event, and the conference was still viable as the date approached. My travels were fairly smooth, and I think, fairly safe. I know there are still challenges, there are people with different levels of comfort with crowds and greetings, and I respect their thoughts.

    From what I see, most people I’ve encountered in Chicago, London, Brussels, and Mechelen just adjust to the rules and how others feel. If someone asks for space, or requests a mask, wants an elbow bump, or is happy to shake hands, others oblige. That gives me hope and optimism for how we will grow and interact in the future.

    I also know that there are still risks involved, especially for unvaccinated people. This event is live, but not hybrid, which inherently cuts out some people that might not be able to attend or be concerned about health. There is a risk of spreading COVID 19, though everyone is supposed to be vaccinated or taking precautions. Travelers were tested coming into Belgium, which may or may not be 100% accurate.

    That’s the world. It’s reality. There is a balance of risk, precaution, reward, restrictions, and life that need to be weighed, but I am confident that most people are making good decisions and complying with the rules.