Category: Blog

  • Daily Coping 21 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 ask for help to overcome an obstacle.

    I hate asking for help. I really struggle with it. Work appreciates that, but my wife sometimes gets on me to share with her and the family.

    I’m working on it.

    I had some chores to do recently, which I could have easily done. Well, not easily, but I likely wouldn’t have hurt myself. Mostly, I’m just slower by myself. I took time to ask my son to help. He’s happy to do it; I just needed to ask and schedule it with him.

    It was nice to work on something together, and it went quicker. Hopefully it survives for a few years.

    20210911_134219

  • Daily Coping 20 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 thank yourself for achieving things you often take for granted.

    I think I get a lot done, and I expect that I will do so. I also tend to just assume these are the things I need to do because I’m responsible, accountable, etc. for these tasks.

    One of the things that I enjoy, but I also know that makes a difference, is I cook dinner. My wife doesn’t like to cook. My son will, but he’d rather not have the burden of deciding on a dish and shopping. If I do those things, he doesn’t mind.

    It’s relaxing for me when I have time, but stressful when I’m busy. However, I also know everyone appreciates it rather than having the throw something together for themselves. It’s a shared chore, not assigned to anyone, but one that I usually take on.

    I somewhat take for granted it’s my job, but I have started to internally recognize that it’s a good thing and I can thank myself.

  • Daily Coping 19 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 make progress on a project or task you’ve been avoiding.

    I have a lot of projects. Work, home, hobbies, and more. I rarely have a day when I don’t feel there is something I should be doing.

    I am also good at avoiding some projects. For various reasons, I will delay certain things over and over. During the lockdown, I was a bit better at tackling some long overdue projects, but not all of them.

    This year, I’d been putting off cutting the grass in the fields at the ranch. I regularly cut the green grass by the house, but the larger pastures need mowing once a year to knock down yucca plants and clean out some of the weeds that grow. When I do this once a year, we end up with healthier grasses the following year.

    However, this is a project. It’s about 30-40 hours of mowing on the tractor. I kept delaying it, mostly because the tractor is behind two gates, and it’s a pain to get out. It also has to go back every day or two because it’s used to load hay into wagons. As a result, my plan to get the pasture mowed this fall was getting delayed. Finally I started just before my trip to Europe. I got the tractor out, attached the mower, and starting cutting. I had timed this so I had an afternoon and the next morning before the tractor was needed for hay. I spent about 5-6 hours across two days getting going on this project.

    I got back from Europe and decided this was a relatively easy project to work on this past Sunday. 3 more hours, and things are looking better.

    20211002_160450

    Now I need to just keep going across the next few weeks, doing an hour or two a few days a week and hope to get done before October ends.

  • 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.