Tag: community

  • T-SQL Tuesday #191 Normalizing Comma Data

    If you’ve escaped string parsing thus far, count thyself lucky. I’ve seen some numbing scripts from pre-SQL Server 2016 when STRING_SPLIT was introduced. I think the fact this month’s T-SQL Tuesday is entirely on string parsing says enough about how many ways there are to paint this particular cat.

    I’ve been using the IMDb’s public dataset since my early days of presenting. AdventureWorks is great, but why not have demos with movie data I can make fun graphics about Lord of the Rings with? Having used IMDb the website all the time I figured I knew what sort of information I was going to get. What I did not expect was this file of writers and directors by title despite the existence of a cast file that also contains, surprise surprise, writers and directors.

    This is a different though overlapping list that must now by normalized to flesh out my cast table. I’ve loaded the file to TitletoDirectorWriter matching the file schema one-to-one. Foreshadowing dictates using STRING_SPLIT() to solve this problem.

    My initial exposure to STRING_SPLIT() was when parsing a comma delimited list of values for reporting.

    DECLARE @ItemTypes nvarchar(max) = 'Reverse,Skip,Draw4,Draw2,WildCard'

    I also grew up learning CROSS APPLY and OUTER APPLY were of the devil and not to be used, but over the last few years I’ve started to see the light. They have a place, and this is one of them.

    SELECT tdw.TitleId [TitleId]
    	,Writer.Value [PersonId]
    	,WriterPersonIds
    	,'Writer' [Category]
    FROM TitleToDirectorWriter tdw
    CROSS APPLY STRING_SPLIT(WriterPersonIds, ',') [Writer]
    WHERE WriterPersonIds IS NOT NULL
    UNION ALL 
    SELECT tdw.TitleId [TitleId]
    	,Director.Value [DirectorId]
    	,DirectorPersonIds
    	,'Director' [Role]
    FROM TitleToDirectorWriter tdw
    CROSS APPLY STRING_SPLIT(DirectorPersonIds, ',') [Director] 
    Where DirectorPersonIds IS NOT NULL
    ORDER BY TitleId

    We get the following results with some potentially unexpected behavior.

    SQL Server doesn’t like making promises, especially when it comes to returning ordered data.
    SELECT TOP 1 Name FROM YourTable with no order by, and you’re gonna have a bad time. STRING_SPLIT() is no different, or at least it was. SQL Server 2022 brought to us a third argument enable_ordinal. Now if we adjust our script to include the original column from our string split with the extra argument passed in we can guarantee the order of our results.

    SELECT tdw.TitleId [TitleId]
    	,Writer.Value [PersonId]
    	,Writer.ordinal
    	,WriterPersonIds
    	,'Writer' [Category]
    FROM TitleToDirectorWriter tdw
    CROSS APPLY STRING_SPLIT(WriterPersonIds, ',', 1) [Writer]
    WHERE WriterPersonIds IS NOT NULL
    
    UNION ALL
    
    SELECT tdw.TitleId [TitleId]
    	,Director.Value [DirectorId]
    	,Director.ordinal
    	,DirectorPersonIds
    	,'Director' [Role]
    FROM TitleToDirectorWriter tdw
    CROSS APPLY STRING_SPLIT(DirectorPersonIds, ',', 1) [Director]
    WHERE DirectorPersonIds IS NOT NULL
    ORDER BY TitleId
    	,ordinal

    Here’s to October and many more T-SQL Tuesdays.

    Random Fun Fact: Plastic Tupperware containers are most easily closed by pressing down firmly in the center, not fussing along the outside lip of the lid.

  • Community Networking

    Community Networking

    One of the scariest parts of attending large events is the number of people and how overwhelming it can be to find safe harbor. I promise that place exists. It may just take time to find it. Fortunately for me, I’m often considered aggressively friendly in that I will talk to anyone, and I’m not afraid to initiate conversations with lone wolves or deer-in-the-headlights folks. Feeling wary? Here are the guidelines I follow when attending new events. I sincerely hope they help you, too.

    1. Be yourself. I would rather people know who I am as a real person than be blind-sided when I show up with a new shade of green or laugh myself into a coughing fit.
    2. Assume people are there to engage. Who really wants to spend hundreds of dollars or sacrifice a whole Saturday just to sit in a room and listen to a bunch of people talking for 8 hours straight? Pre-cons aside.
    3. Look for people you know. I see so many familiar faces the more events I attend, and it won’t take long for you to get there. One conversation later, six degrees of separation kicks in and suddenly you know more people, too.
    4. Find a group of three or more people and join their circle. You may meet someone important on accident, have something to contribute to a discussion, or just absorb information. There’s nothing stopping you from joining a 1v1, but unless I know one of them personally I don’t. Even then, eh.
    5. The more intimidating version is to look for people who seem lost or unsure. I made a great new friend last PASS because I saw some random dude looking around and assumed he was lost. Nope. Growing speaker in the community that was less than lost, knew way more people than me, and here I was trying to help him.
    6. Visit vendor booths. At worst you learn about a new tech out there, and at best you find a software solution that fits your needs to bring back to work and look awesome. One year I randomly talked to a vendor at an evening event, unbeknownst to me, and I got to have dinner at their booth to hang out the next day. Great conversation with cool people that weren’t there just to shove a product at me.
    7. Connect. Shorten the degree of separation if you jive and add them on LinkedIn during or after engaging. Your connections on LinkedIn help you see what else is going on in our community, learn tips you never knew you needed, and potentially help someone land a new job. Maybe even you one day.
    8. Speaking of jiving, don’t expect to experience it with everyone. It’s ok if a conversation falls flat, or there doesn’t seem to be a good flow between you. It is normal. Don’t see it as a failure to communicate adequately and certainly not a reason to give up on this whole networking thing. There are plenty of people in the world.
    9. If you see me and my obnoxious hair at an event, please say hi. Feeling lost or overwhelmed? Please say hi. I will happily help you integrate with a conversation to parachute your initial jump.

    Five years ago, I had no idea what a user group was or that tech conferences existed for those of us that had never installed Visual Studio let alone run git commit. One day while perusing the internet trying to find the answer to some mystery, I ran into the SQL Community slack channel and found the beginnings of the next adventure in my career. What drew me in was the opportunity to help others and learn, but what’s kept me there are the people.

    I was recently asked by Andy Levy (post) to help recreate the exchange that really got me into speaking for T-SQL Tuesday. It’s a fun read if I do say so myself and a great anecdote on the importance of having these spur of the moment conversations. The density of people in our field eager to encourage others is nothing short of astounding. The more you open yourself up to meeting new people and trying new things, the greater your chances are of discovering something grand.

    Always aim to surround yourself with those that bring out the best in you and strive to be that person for others.

    Leave a comment