Tag: syndicated

  • SQL Saturday #77 – Pensacola Recap

    sqlsat77_bThis past weekend I went down to Pensacola, FL for SQL Saturday #77. This was the third event in Pensacola, and my third time going down there. It was also the second time that I brought my daughter along for the trip. She had a great time the first time, and was good about spending Fri night and Saturday at the event in exchange for a couple days in Pensacola.

    Me, Tim Radney, and Karla Landrum

    I arrived early, on Thursday, spending all day Friday with my daughter until the speaker party on Friday night. The opening event was amazing, at Hemingway’s Island Grill, just across the causeway at Pensacola Beach, on a deck looking out over the water. With a cool evening, we couldn’t have asked for a better setting where I had the chance to sit and talk with Aaron Nelson a bit, met Wayne Sheffield for the first time, and of course, sp

    ent time with Karla Landrum as well.

    sqlsat77_a

    The coolest shirts were available for speakers, me being above, and separate shirts for the women. My daughter, and Aaron’s daughter, got shirts as well, and you can see them here. My little girl loved hers and wore is as much as she could all weekend. I don’t think speaker shirts are necessary, but they are a nice touch, and I love the creative ones I’ve gotten at this event, Cleveland, and Baton Rouge last year.

    The event was held at a local college, as it has the last three years. The entrance and building moved this year, mostly because the Mac user group refused to move their meeting or give up the auditorium they have, so boo on them. In any case, there was a motorcycle class happening in one parking lot, which caused a number of people to get confused as where to go. We suspect a few people were annoyed and left, which is something to be aware of. Ask about any potential traffic situations on the day of the event that might be going on.

    I arrived a bit late, and the event was quiet. Everyone was in sessions except a few speakers and vendors were learning something. With sessions spread out across two buildings, it was definitely a calmer event than I’ve seen in the past. The vendors had a nice walkway through the entrance hallway, on the way to food, and they had good traffic at lunch and as people were leaving. However I’m not sure how well this layout worked during the day as people could go from session to session without moving past tables.

    I realize that sponsorship is a tricky thing to balance with not annoying attendees but also allowing vendors a chance to get value for their sponsorship. I think I’d like to see vendors in between session rooms, giving people a chance to talk by, or vendors to show off some video or demos as people walk by.

    My first session was just before lunch, in the far building, and I had good attendance. With my daughter laying down in front of the room with a DVD, I delivered my talk on Branding Yourself for a Dream Job – The Modern Resume. I had about 40 or so people in there, with a mix of people looking for work, looking for new work, and just interested. I got some great comments, and people said nice things afterwards, even though it was a quiet crowd, and hard to get them to interact with me.

    sqlsat77_eI had a short break before a lunchtime Red Gate demo session, which was very well attended. Again, about 40-50 people watched me demo a few tools, showing them a few ways in which Red Gate tools make life easier. Right after lunch, I had a third session in a row, my Preparation for Disaster, a look at the types of things that need to go into preparing for things to go wrong with SQL Server. It’s a basic session, and perhaps it wasn’t well described as I only had about 10 people in there. However they seemed to like the session from the comments.

    After that I left for a break, my voice tired, and my daughter wanting a chance to swim a little before the after party. We arrived as the party was getting going, walking in with a few other people. It was a Rosie O’Grady’s with the old fashioned fire truck out front in Pensacola downtown. I had the chance to chat with a few more people, eat some great BBQ, and relax for a bit. With the iPad in hand, my daughter and Aaron’s little girl occupied themselves for quite awhile.

    Aaron, me, and our not-so-little girls

    I think I was expecting a busier event, but last year TechEd was the week after this event, and a short drive over to New Orleans, so there were quite a few more people I knew coming to speak. This year it was quieter, more restrained, but still a great event. Pensacola is a beautiful place, great beaches, and worth taking a day or two extra to relax on the gulf coast after some SQL Server learning.

    My daughter is already asking if we can come back next year.

  • Combinations and Permutations

    I ran into an interesting question from someone asking for all combinations of numbers. The thread was here, and it was confusing at first. However we started to understand what was being asked and eventually the person stopped, realizing that there were too many combinations.

    However at one point there was this quote: I’m looking for combinations, not permutations since the order is unimportant.

    That surprised me since I was thinking of things in the opposite manner. However when I read this article, it made sense: combinations and permutations

    There is a table in the article that cleared it up. I’ve reproduced it here:

    Order does matter Order doesn’t matter

    1 2 3

     

    1 3 2

     

    2 1 3

    1 2 3

    2 3 1

     

    3 1 2

     

    3 2 1

    The left hand side is permutations, where order matters. The right hand side is combinations, of which there is only one. Order doesn’t matter so 1-2-3 is the same as 1-3-2, which is the same as 3-2-1 and all other orderings.

    This shows mathematical semantics, but those are important in SQL because we do need to talk about combinations and permutations. A CROSS JOIN is normally how we handle combinations, which for three numbers are usually thought of as the way to handle all combinations, but I’m not sure how that works here.

    If I create a quick table:

    CREATE TABLE Combinations
    ( id int) GO INSERT Combinations select 1
    INSERT Combinations select 2
    INSERT Combinations select 3

    and then perform a cross join:

    SELECT a.id, b.id
     FROM Combinations a
       CROSS JOIN dbo.Combinations b

    I get this:

    id          id

    ———– ———–

    1           1

    2           1

    3           1

    1           2

    2           2

    3           2

    1           3

    2           3

    3           3

    Not all combinations. Even if I add in a third result:

    SELECT a.id, b.id, c.id
     FROM Combinations a
       CROSS JOIN dbo.Combinations b
       CROSS JOIN dbo.Combinations c

    id          id          id

    ———– ———– ———–

    1           1           1

    1           2           1

    1           3           1

    1           1           2

    1           2           2

    1           3           2

    1           1           3

    1           2           3

    1           3           3

    2           1           1

    2           2           1

    2           3           1

    2           1           2

    2           2           2

    2           3           2

    2           1           3

    2           2           3

    2           3           3

    3           1           1

    3           2           1

    3           3           1

    3           1           2

    3           2           2

    3           3           2

    3           1           3

    3           2           3

    3           3           3

    However, what about if I limit the result to remove duplicates:

    SELECT a.id, b.id, c.id
     FROM Combinations a
       CROSS JOIN dbo.Combinations b
       CROSS JOIN dbo.Combinations c
    WHERE a.id != b.id
    AND b.id != c.id
    AND a.id != c.id

    That seems to work better:

    id          id          id

    ———– ———– ———–

    1           3           2

    1           2           3

    2           3           1

    2           1           3

    3           2           1

    3           1           2

    However that’s not a great solution. I’ve hardcoded the number of items, and it’s a cumbersome query. I think there has to be a better solution, but it’s probably one that’s beyond my T-SQL skills. If I look at 5 numbers, I get this:

    SELECT a.id 'a', b.id 'b', c.id 'c', d.id 'd', e.id 'e' FROM Combinations a
       CROSS JOIN dbo.Combinations b
       CROSS JOIN dbo.Combinations c
       CROSS JOIN dbo.Combinations d
       CROSS JOIN dbo.Combinations e
    WHERE a.id != b.id
    AND a.id != c.id
    AND a.id != d.id
    AND a.id != e.id
    AND b.id != c.id
    AND b.id != d.id
    AND b.id != e.id
    AND c.id != d.id
    AND c.id != e.id
    AND d.id != e.id
    ORDER BY a, b, c, d

    I get 120 rows. If I look at 5!, that’s 120, so I think I’m correct. I’m not duplicating all the results, nor am I  going to look through them all, but they seem correct and ordered.

    The thing this solution leaves out is the combinations that are less than the total number of items, as asked in the thread. So expanded combinations would be:

    1

    2

    3

    4

    5

    1 – 2

    1 – 3

    1 – 4

    1 – 4

    1 – 2 – 3

    Not worth including those, but I think that would result in a series of UNION queries, which would get really ugly.

    I’ll ask around, but if anyone has an interesting way to solve this that’s cleaner, I’d be interested.

    Update

    Someone posted this, which seems to work wonderfully:

    DECLARE @s VARCHAR(25)
    ,@Iteration Int
    SET @s = ‘ABC’;
    SET @Iteration = LEN(@s);

    WITH E1(N) AS ( –=== Create Ten 1’s
    SELECT 1 UNION ALL SELECT 1 UNION ALL
    SELECT 1 UNION ALL SELECT 1 UNION ALL
    SELECT 1 UNION ALL SELECT 1 UNION ALL
    SELECT 1 UNION ALL SELECT 1 UNION ALL
    SELECT 1 UNION ALL SELECT 1 –10
    ),
    cteTally(N) AS (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT N)) FROM E1
    ),CteCombos AS (
    SELECT CAST(SUBSTRING(@s, N, 1) AS VARCHAR(25)) AS Token,
    CAST(‘.’+CAST(N AS CHAR(1))+’.’ AS VARCHAR(52)) AS Permutation,
    CAST(1 AS INT) AS Iteration
    FROM cteTally WHERE N <= @Iteration
    UNION ALL
    SELECT CAST(Token+SUBSTRING(@s, N, 1) AS VARCHAR(25)) AS Token,
    CAST(Permutation+CAST(N AS CHAR(1))+’.’ AS VARCHAR(52)) AS
    Permutation,
    s.Iteration + 1 AS Iteration
    FROM CteCombos s
    INNER JOIN cteTally n
    ON s.Permutation NOT LIKE ‘%.’+CAST(N AS CHAR(1))+’.%’
    AND s.Iteration < @Iteration
    AND N <= @Iteration
    )
    SELECT Token,Permutation,Iteration
    FROM CteCombos
    WHERE Iteration = @Iteration
    ORDER BY Permutation

    If you alter the variable (abc) to the number of items you need, so “abcde” for 5, this returns the combinations.

  • A Welcome Break

    I’m not working, though I have checked some email and kept an eye on a few things while I’m in Pensacola, FL. I have made an effort, however, to not work, and not respond to emails that weren’t very time critical. Mostly I’m just trying to prune down things that might make my return hard.

    SQL Saturday #77 was Saturday, and while Friday night and most of Saturday were consumed by the event (which was great, I’ll write tomorrow), most of Friday, Sunday, and today are vacation for me. I brought my daughter with me, and it’s been a fun trip for us. We’ve gotten to enjoy some sights together, but mostly just hang around, getting some great quality time.

    I don’t usually take all my vacation, despite the ski days that I sneak in here and there, and that has started to bother me the last couple years. The nature of my job makes it hard to get away, but I’m making an effort this year, with a couple short vacations done and a couple more planned.

    We’ll see how I do this year, but for now I’m enjoying the break.

  • Duplicate Identity Values?

    Can you have duplicate values in a field with the identity property? Of course, and this does it.

    DROP TABLE dbo.MyTable
    
    CREATE TABLE mytable
    ( id INT IDENTITY(1,1)
    , mychar VARCHAR(10)
    )
    GO
    INSERT mytable SELECT 'A'
    INSERT mytable SELECT 'B'
    INSERT mytable SELECT 'C'
    
    
    SELECT * FROM dbo.MyTable

    This returns these values:

    result1

    Then we use Identity_insert

    SET IDENTITY_INSERT dbo.MyTable ON
    GO
    INSERT dbo.MyTable
            ( ID, myChar )
    VALUES  ( 8, -- myID - int
              'H'  -- myChar - varchar(20)
              )
    SET IDENTITY_INSERT dbo.MyTable OFF
    
    SELECT * FROM dbo.MyTable

    result2

    Now we reseed and add more values

    DBCC CHECKIDENT('mytable', RESEED, 4)
    
    INSERT mytable SELECT 'E'
    INSERT mytable SELECT 'F'
    INSERT mytable SELECT 'G'
    INSERT mytable SELECT 'H'
    INSERT mytable SELECT 'I'
    
    SELECT * FROM dbo.MyTable

    result3

     

    You can see that we have two ID rows with “8” in them. Clearly a duplicate.

    Identity doesn’t guarantee uniqueness. If you want that, make a PK or add a unique index.