OT: Riding In To Work (Motorcycle)

I have been riding in to work by motorcycle for the last 4 months. I got my motorcycle endorsement at the end of April. I took the Team Oregon Basic Rider Training before getting my endorsement. It was a very fun class. And I really felt prepared to ride on the road after it. So, I'd recommend it or it's equivalent in your state.

There were a few reasons that I got a motorcycle. One was to just do something different. You know, shake things up. Another was to save some money. With selling my car and getting a cheap motorcycle, I was able to knock a few grand off my credit cards. :-) Also, I'm getting about 55 MPG. When I fill up, it's like $8. Oh, and insurance is like $160/year.

Since I was a new rider, I figured I should get a very cheap bike. That way, I wouldn't cry if I happened to lay it down. So, I got a 1981 Honda CM400 Custom. Here is a picture of my commuter bike. I've already put on almost 2000 miles.

Anyone else ride a motorcycle in to work?

SQL Server - Insert Not Working

Just wanted to share a bit of fun I had yesterday. (Actually it wasn't very fun). I had a cfquery that was supposed to copy "Template" records linked to one entity inserting them linked to another entity. So, the file was using an Insert/Select. Never seen one? OK, it looks like this.

<cfquery datasource="#request.DSN#">
      INSERT INTO
         [Template]
         (
            TemplateName,
            OwnerID,
            ...
         )
      SELECT
         TemplateName,
         <cfqueryparam value="#attributes.Target_OwnerID#" cfsqltype="cf_sql_integer">,
         ...
      FROM
         [Template]
      WHERE
         OwnerID = <cfqueryparam value="#attributes.Template_OwnerID#" cfsqltype="cf_sql_integer">
         ...
   </cfquery>

So, we can all agree that insert/select is a great thing. However, this particular one was not working (on the live server). I tried the normal things. I cut the SQL from the .cfm and pasted it into SQL Server Management Studio (SSMS), replaced the params with the values I knew it would be using and ran it (inside of a transaction, of course). Guess what? It worked. So, it works running in SSMS but, not in a cfquery. Hmmm... So, next, I added an "output" clause to the insert/select. That way I could see any records it would be inserting, just to make sure it really wasn't inserting them. Then I added a cfdump that would only run for me. "What's an output clause?" you say. Here I'll show you.

<cfquery name="insTemplates" datasource="#request.DSN#">
      INSERT INTO
         [Template]
         (
            TemplateName,
            OwnerID,
            ...
         )
      OUTPUT
         INSERTED.*
      SELECT
         TemplateName,
         <cfqueryparam value="#attributes.Target_OwnerID#" cfsqltype="cf_sql_integer">,
         ...
      FROM
         [Template]
      WHERE
         OwnerID = <cfqueryparam value="#attributes.Template_OwnerID#" cfsqltype="cf_sql_integer">
         ...
   </cfquery>
   <cfdump var="#insTemplates#" label="insTemplates" />

I ran that and guess how many records were inserted... 0. At this point I'm a bit frustrated. But, it begins to dawn on me that I've seen similar behavior before from SQL Server. There are time when the SQL Server will cache a bad plan for some SQL. In these cases, you can either have the database flush it's entire plan cache or you can alter the SQL enough to force it to make a new plan for your SQL. So, I added "AND 1=1" to my "where" clause.

Guess what? It works now.

This is a fairly edge case. I have not seen it very often. But, if you are positive that a cfquery is not returning what it should, before you jump out of your office window, try adding something innocuous to your "where" clause.

If it does work, feel free to send some happy thoughts my way and curse MS under your breath. :-)

I'm an Adobe UG Co-Manager!

As part of a new Adobe initiatives user groups are supposed to have co-managers. So, I will be the new co-manager for the PDXRIA group. The title feels a little like "Assistant to the Regional Manager" ;-). And in more exiting news, Simeon Bateman will be stepping back up as the main manager.

We will both do our best to provide engaging presentations and valuable opportunities for networking. For more details see Simeon's blog.

P.S. I'm going to try and blog more often.

BlogCFC was created by Raymond Camden. This blog is running version 5.6.002.