View Full Version : SQLServer UPDATE - Concatenation

02-18-2008, 05:51 PM
Hi, I have a field in an SQLServer database, and I need to add a string to the end of the existing content. Is it possible to do this in a single UPDATE query?

I guess it would be possible using a sub-query, such as:

UPDATE table SET column='(SELECT column FROM table WHERE columnID=ID)"&newString&"' WHERE columnID=ID

but Im keen to know if I can do it with a single query...

02-18-2008, 08:20 PM
Concatenate the column onto itself with the added text:

UPDATE table SET column = column + ' some value'

Good luck.

02-19-2008, 10:22 AM
Thanks for the reply brandoe.

Your theory was correct, only a slight alteration was required to avoid a data type error (data types text and varchar are incompatible in the add operator).

This is the working code:

UPDATE table SET column=Convert(VarChar(80),column) + Convert(VarChar(80),'"&some value&"')

02-19-2008, 10:29 AM
if anyone else is having a similar issue with data type concatenation, heres a link to the solution that worked for me.