Sunday, September 20, 2009

My Boy

IMG_5240This morning I cut Desmond’s hair out on the patio.  He did fairly well while I tried to entertain him with things outside of his normal toy repertoire.  (The floss lasted the longest.)  After we were done he was running around with his shirt off carrying the stick we use to bar the patio door.  Such a good boy picture.  I love it!

 

LightSaberDes

 

Daddy’s boy carries a more powerful weapon.  The force is strong with our little one!

Saturday, September 19, 2009

Pivoting SQL Data

So, the other day I was trying to pivot some SQL data that was basically in this format...

RecNumber ColNumber FieldName FieldValue
1 1 FirstName Davin
1 2 LastName Studer
2 1 FirstName Melissa
2 2 LastName Studer

I wanted to see it like this ...

RecNumber FirstName LastName
1 Davin Studer
2 Melissa Studer

It took me a while to figure out the syntax for this, but here it is. It uses the SQL pivot keyword.

This first portion dynamically creates the column names to be used in the pivot.

declare @cols varchar(max)

    select  @cols = stuff (
        (
            select '], [' + FieldName
            from table
            group by FieldName
            order by min(ColNumber)
            for
            xml path('')
        )
        , 1, 2, ''
    ) + ']'

This next part creates a query within a string that we will run with the SQL exec command.

declare @query varchar(max)

    set @query = '
    select RecNumber, ' + @cols + '
    from (
        select RecNumber, FieldName, FieldValue
        from table
    ) dta
    pivot
    (
        min(FieldValue)
        for FieldName in (' + @cols + ')
    ) pvt'

All that is left to do is to execute the query that was created. I ended up putting this into a stored procedure.

exec(@query)

Catching Up on the Last Month

IMG_5109 IMG_5094 

We enjoyed a family hike with fellow Baby Boot Campers to the top of Multnomah Falls at the end of August.  It was a good hike and an even a better work out carrying Desmond.

IMG_5192 IMG_5199 

Desmond walking around the zoo.  We forgot the stroller and he LOVED his freedom!  Des and I visit the zoo often with our friends Gina and Addison.  The kiddos really enjoy playing together.

IMG_5218The strange rash Desmond broke out with after eating hummus – which he’s had before with no reaction.  He also broke out like this after eating a cinnamon sugar pretzel.  Hmmm.

IMG_0016 IMG_0019 

Fun at the state fair!  Desmond’s favorite part was the corn bin.  He did NOT want to get out.

IMG_5230 IMG_5234

Playing at home: This week I pulled out my little table and chairs from when I was a kid.  Desmond thinks it’s so cool.  He also loves carrying around the new Twistables crayons.  He doesn’t color much yet, but at least he can’t eat them now.