Skip to content

Concatenating Parameters In A SQL Statement Are Empty

October 22, 2012

Here is one of those things that happened and once I saw it, I knew it was wrong but I spent way more time debugging than I should have.

Here’s the scenario:
Stored procedure was to load some data from a staging table and create some contracts in GP. For some reason one of the values was being assigned improperly. The value for record 1 was being put into record 2 but all of the other values were correct. Upon further investigation, I noticed that the very first record was empty and it’s value was subsequently put (incorrectly) into record two and that continued for all of the records.

Code looked something like this:

Declare @parm1 varchar(10),
@parm2 varchar(10),
@parm3 varchar(30)

@parm1 = column1
, @parm2=column2
, @parm3 = @parm1 + char(13) + @parm2

So here I was debugging the code only to realize the assignment of the params that were being used were not really “available” until after the select was completed which is what was causing our problem. A simple change to @parm3 = column1 + char(13) + column2 fixed the problem and life was good again.

Don’t you love inherited code?

So now the question is, how do I tag this so others can find it. My variables have values but concatenating failed ? Leave me a comment with how you found this post and if it helped, what might have made it easier to find. Then again, maybe nobody else has ever done this or inherited code that did and I’m all alone in this one, it wouldn’t be the first time.


From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: