May 20, 2004 at 4:40 am
WHAT I WANT TO DO IS CONCAT THE CONTENTS OF THESE INDIVIDUAL VARIABLES AND STORE IT IN A DIFFERENT VARIABLE BUT ITS NOT HAPPENING
i have a code like this
--------------
set @msgContent= 'Complaint Code ' + @ComplaintCode + 'Invoice No.' + @invoiceno + 'Batch No.' + @Batchno
--- ERROR MESSAGE
Error converting data type varchar to numeric.
<a href="http://www.websolsoftware.com"> For IT jobs click here</a>
*Sukhoi*[font="Arial Narrow"][/font]
May 20, 2004 at 5:24 am
Sukhoi,
It's funny how the error message is sometimes the opposite of what it should be...
Your problem is that the contents of one or more of your variables are numeric and need to be converted to VarChar. Depending on your server settings, you may also have to be careful about NULLS. The default server setting say that when you concatenate nulls with anything else, the answer will be NULL. I don't recommend changing that server setting because you could really mess up JOIN conditions.
If all of your variables are numeric and guaranteed to never be NULL, try this...
Notice I added a couple of spaces to your string literals to provide a little output spacing.
If all of the variables could contain NULLs, the statment gets a little longer...
Of course, you may have to change VARCHAR(10) to a different length but 10 works for INT and most other integer datatypes (so would 9). You may also want to change '-None-' to something else (maybe 'NULL' or ' ') to represent NULLs in your output.
One other thing... you may have to read your own code in the future... make it easy on yourself... instead of putting all that code in a single long line (which will wrap or truncate during printing), do a little formatting like I did in my example.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply