...

View Full Version : SQLServer UPDATE - Concatenation



adamskii
02-18-2008, 04: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...

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


UPDATE table SET column = column + ' some value'


Good luck.

adamskii
02-19-2008, 09: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&"')

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

http://www.thescripts.com/forum/thread570278.html

:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum