Category: Blog

  • Daily Coping 7 Jan 2022

    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 get outside and pick up litter or do something kind for the planet.

    I do try to pay attention when I’m walking around, and I pick up litter I see. It’s a bit of a habit when I’m in a volleyball gym as well. I do make sure my kids clean up, but others kids and parents aren’t always paying attention, so I usually end up grabbing a few things from chairs and floors.

    I haven’t done this much on my property, so I took a walk around the perimeter recently, looking for trash that had blown away or torn up by dogs. I took a plastic bag with me and picked up some trash.

  • Daily Coping 6 Jan 2022

    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 let someone in your life know how much you appreciate their presence.

    Easy to do to for family, and something I’d recommend you do often. It’s nice to hear that your loved ones appreciate you, and I try to remember to let them know.

    I don’t do enough of this with friends, but I reached out to a friend that I have lunch with periodically and let him know that I enjoy his company, whether we get together or not. I’m making it a point to try and get together more often with him this year. We used to have lunch almost every month, and I need to get back to that.

  • Finding the First Day of the Year–#SQLNewBlogger

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

    While working on the question from Monday, I had to do a bit of date math. I remember this blog post from Lynn Pettis, and every new year I think of it.

    I decided to decode the question a bit and work through the T-SQL myself as a good exercise for explaining what happens.

    Here’s the code (setup and query):

    CREATE TABLE dbo.Resolution
    ( ResolutionDate DATETIME
    , ResolutionText VARCHAR(200)
    )
    GO
    INSERT dbo.Resolution
    (
         ResolutionDate,
         ResolutionText
    )
    VALUES
       ('2020-01-01 0:00', 'Do not travel by airplane this year'),
       ('2021-01-01 0:00', 'Go on vacation on a plane'),
       ('2022-01-01 0:00', 'Visit a new country')
    GO
    SELECT ResolutionText FROM  dbo.Resolution
    WHERE ResolutionDate = DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) , 0)

    In this code, the final query is designed to find the first day of the current year. Here are a few examples:

    2021-12-01 09_45_54-SQLQuery3.sql - ARISTOTLE_SQL2017.sandbox (ARISTOTLE_Steve (56))_ - Microsoft SQ

    How does this work? Let’s decode things.

    Digging Into the Algorithm

    Let’s start with a simple thing. I use a 0 for a parameter in the DATEADD and DATEDIFF. What does that mean? Well, let’s go with the YEAR() function. If I use a 0 there, I see the base year in SQL Server, which is 1900.

    2021-12-01 09_47_42-SQLQuery3.sql - ARISTOTLE_SQL2017.sandbox (ARISTOTLE_Steve (56))_ - Microsoft SQ

    This doesn’t mean I can’t use other years, but this is the basis for calculations. What if I add to this? I can add one, and I see a different date.

    2021-12-01 09_48_45-SQLQuery3.sql - ARISTOTLE_SQL2017.sandbox (ARISTOTLE_Steve (56))_ - Microsoft SQ

    This is the key. I’ve gone from 0 to 1901-01-01-00:00:00. Let’s see the difference from this year, well last year when I wrote this, to 0.

    2021-12-01 09_49_44-SQLQuery3.sql - ARISTOTLE_SQL2017.sandbox (ARISTOTLE_Steve (56))_ - Microsoft SQ

    The result above shows me 121. Which makes sense. 1900 to 2021 is 121 years. Now, when I use the dateadd, and add 121 to 0, I get the first day, actually the first DATETIME moment, of the current year.

    2021-12-01 09_50_41-SQLQuery3.sql - ARISTOTLE_SQL2017.sandbox (ARISTOTLE_Steve (56))_ - Microsoft SQ

    I get 2021-01-01 00:00:00.

    I can change the GETDATE() to any date time of any year, and this code returns the first moment of that year, essentially stripping off the other parts.

    SQLNewBlogger

    I was working on something and used a trick I learned from someone else. I decided to write this post, which only took about 15 minutes to write. The demo was simple, and I just broke apart the code, slowly putting each section in its own SELECT and then explaining it.

    This is a good example of how to structure a blog post based on some knowledge you have and use in other work. You should try this.

  • Daily Coping 5 Jan 2022

    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 plan an act of kindness towards another.

    Obviously I don’t want to disclose this before I do it, but this was a good one. I had to think a bit here and decide what I should do for someone else.

    It did a small thing, but an item I think matters. My daughter was coming home from college. I usually keep her plant alive while she’s gone and it’s been a habit of mine to clean her sheets and remake her bed before she returns.

    This time I added something else. She’s gluten sensitive, which isn’t a big deal for me to cook, but I’ve gotten out of the habit of having stuff around she can eat. It’s been nearly 5 months since I’ve worried about gluten.

    I swung by the store after the gym the day she returned. I didn’t really need anything, but I grabbed some gluten free bagels and dropped them in the fridge. When she got come from the airport, she noticed and was thrilled. Gave her something for breakfast the next morning.

    A small thing, but a bit of joy that was easy to create by thinking of someone.