Tag: T-SQL Tuesday

  • Puzzles–T-SQL Tuesday #114

    This month we have a very interesting topic from Matthew McGiffen. He gets back to the roots of the party with code by asking a question on puzzles. It’s a good question, and one that makes me think. I’m not a big puzzler, but I think I’ve solved a few.

    Interesting Challenges

    One of the things we’ve tried to do at SQLServerCental is come up with some ways to inspire you. We have articles, numerous questions to be answered, our Question of the Day, Crosswords, and more. I’d like to do more, but one thing I’ve found is that puzzles take a lot of time.

    I have enjoyed some of the puzzles from the Advent of Code and Project Euler, which are good programming exercises. I’ve used Python and PowerShell to solve some of these, mostly to practice skills in building algorithms and implementing them.

    Solving a Puzzle

    One of the puzzles that I enjoyed solving was from the Advent of Code 2015, Day 2. This was a surface area problem, and one that reminded me of math class in high school. I always did enjoy that subject.

    In any case, I solved the issue by loading some data into a table and then digging in with a  few CTEs to

    Might not be the best solution, but it was one I enjoyed working out:

    ---- create table

    --create table Day2_WrappingPresents

    --(

    -- dimensions varchar(100)

    --)

    --go

    ---- load data

    --bulk insert Day2_WrappingPresents

    -- from 'C:\Users\Steve\Documents\GitHub\AdventofCode\Day 2 - Wrapping\input.txt'

    --go

    ---- check

    ---- select * from Day2_WrappingPresents

    --go

    -- break this down to get the dimensions

    with cteSplit (d, el, sw, sh)

    as

    (

    select

    dimensions

    , endlength = charindex('x', dimensions) - 1

    , startwidth = charindex('x', substring(dimensions, charindex('x', dimensions),20)) + charindex('x', dimensions)

    , startheight = len(dimensions) - charindex('x', reverse(dimensions)) + 2

    -- , c1 = charindex('x', dimensions)

    -- , c2 = charindex('x', dimensions, charindex('x', dimensions)+1) -

    from day2_wrappingpresents d

    )

    , cteDimensions

    as

    (select

    d

    , l = cast(substring(d, 1, el) as int)

    , w = cast(substring(d, sw, sh-sw-1) as int)

    , h = cast(substring(d, sh, len(d)) as int)

    from cteSplit d

    )

    , cteOrder

    as

    ( select

    d

    , small = case

    when l <= w and l <= h then l

    when w <= l and w <= h then w

    when h <= l and h <= w then h

    end

    , middle = case

    when (l >= w and l <= h) or (l <= w and l >= h) then l

    when (w >= l and w <= h) or (w <= l and w >= h) then w

    when (h >= l and h <= w) or (h <= l and h >= w) then h

    end

    , large = case

    when l >= w and l >= h then l

    when w >= l and w >= h then w

    when h >= l and h >= w then h

    end

    from cteDimensions

    )

    , cteFinal

    as

    (

    select

    d

    , area = (2 * small * middle) +

    (2 * small * large) +

         (2 * middle * large)

    , slack = (small * middle)

    from cteOrder

    )

    select

    sum(area + slack)

    from cteFinal

    -- drop table Day2_WrappingPresents


  • T-SQL Tuesday #113–Personal Databases

    This month we have a really interesting question for the T-SQL Tuesday invitation. Todd Kleinhans is the host and asks about personal databases. Do we use them for anything? Quite a create question for a professional.

    My Personal Database

    I don’t really have a lot of databases that are for personal use. I do a lot of testing and I have lots of sample databases from various sources. I have samples from Microsoft, various stats from sports leagues, even one with lots of SQL Saturday stuff (I need to make that one public). However, when I’m away from work, I’m usually away and don’t manage stuff in a database

    Except.

    I started to build one a few years ago to track some aspects of my life. It’ s a work in progress and like many of the databases out there, it’s a mish mosh of various unrelated items. For example, I’ve so far built some entities to track these items:

    • speaking events
    • places I’ve traveled or want to travel
    • a bucket list

    That’s it so far, and there’s no GUI. It’s not even accessible outside my desktop (though I do make backups). I need to move this into the cloud and be able to enter new data in there from any place. My intention is to get this back up in a website about life, maybe with links to pictures I want posted, maybe a visualization of travel, maybe just as a central list of things I’d like to do in life.

    I’m really not sure, but that’s it for now. I may add in exercise or other things in my life where I track data. In fact, that might be the next thing, perhaps sucking data from MapMyrun.com or Garmin Connect, where I’ve stored lots of data. Perhaps an ETL project is in the works here in the future.

  • The T-SQL Tuesday #112 Cookie

    tsqltuesdayIt’s T-SQL Tuesday again, and I’m writing in response to Shane O’Neil’s invitation about cookies. Read what he asks and this will make more sense.

    As always, if you want to participate, write a post on your blog and follow the rules on the invite.

    If you want to host, ping me on Twitter.

    My Cookie

    I’ve had quite a bit of success in my career. I’ve worked hard, and I was lucky to be born intelligent enough to get things done in this field, but I’ve had a lot of help along the way. I don’t want to discount the things others have done for me, whether that’s a favor, an opportunity, or a lesson. This post is about standing on shoulders, my own and others, in a way that still makes me smile today.

    I had a lot of experience programming in the past. I’m not great at it, but I’m effective. A few years ago someone asked about getting a list of the PASS sessions from the DVD that they’d purchase in a data set. They didn’t want to go through the HTML index on the drive, but wanted a better data set to work with the sessions.

    At the time, I had the USB key sitting on my desk. I was doing some R learning at the time and decided to see if I could do something in R. I remembered a few years earlier when Aaron Nelson had helped me with a PowerShell script to download some videos, and I wanted to see if I could do something in R.

    I ended up building a short script that read in the data, cleaned it up, and exported a short R script that contained the session titles, authors, and the MP4 file. It took my only tens of minutes, and I was quite proud of it.

    Actually, I need to blog that script.

    In any case, when I sometimes face a task that is unfamiliar, I remember how I worked through the process and got things working. When I worry about a new technology, I remember how I accomplished this in R, which was new to me.

    It’s a delicious cookie, even today.

  • What is my why?–T-SQL Tuesday #111

    tsqltuesdayThis is an interesting question from Andy Leonard for T-SQL Tuesday: What Is Your “Why”? He is this month’s host and asks us to talk about our motivation, our passion. The question is: Why do you do what you do?

    Why I Do What I Do?

    I have had a great career in technology. Moving from developer to system administrator to developer to manager, and back through various incarnations. I have had success in lots of positions and helped improve systems and code, teaching and mentoring others along the way.

    Almost twenty years ago, I participated in a user group and helped someone solve an issue. That inspired me to start writing articles that detailed how to build solutions that had helped me and my employer. Over time that led to SQLServerCentral and regular speaking and writing.

    My career in databases really started for the money. I worked with a DBA that was better paid than any sysadmin or developer, and began to study and work with SQL Server. As I earned more, I thought I’d made a good decision, but over time I realized that there was a point where money was less important to me.

    Time became the most important thing to me.

    There have been many times where I would have traded more time for less money, though that isn’t quite the case now as I have two children attending college next year. Still, in the middle of my career I wanted to, because of the value that I placed on time with family and friends and living my life.

    I started to give back with writing, speaking, teaching because I had people do that for me, and because I wished I’d had more. I wished that more people had shared solutions and ideas with me earlier in my career.

    I also believe that we fundamentally ought to help others in life when we’ve been helped or been successful. We ought to pay it forward where we can, but more so we need to pay it back. It’s a bit of a social contract with others, a bit of a desire to be the rising tide that lifts all boats, and a bit of a moral obligation I feel to help the world because I’ve been blessed with success.

    Everyone walks their own path, makes their own decisions, and follows their own moral code. I try to follow mine, and I hope to inspire others to help others where they can.

    It’s why I do what I do, and I’m lucky that I’m able to do so, both as my job, but also because I am able to help others.