Skip to content
Advertisement

How do I add text to a column that already has text in it in SQL (I want to add the new text to the end of the text that is currently stored)

I have already looked at the answers on How can I add text to SQL Column. However, I am not sure how to add the text I want to the end of the text that is already stored in the column. Can anyone help? I am using SQL

Advertisement

Answer

In supported versions of SQL Server you can employ one of two options:

SELECT foo + 'some text'
  FROM bar;

or

SELECT CONCAT(foo, 'some text')
  FROM bar;

Persisting that change to the table can be done with an UPDATE that sets the column value to the concatenated value like so:

UPDATE bar
   SET foo = CONCAT(foo, 'some text');

Note that executing this update without a WHERE clause will change data in all the rows of your table and should likely not be done – always strive to define a WHERE clause on your UPDATES

And a note to improve you question quality: “SQL” is a generic term for a language (the Structured Query Language) that has standard specifications that have been implemented in (sometimes very) different ways by different vendors. Please try to be specific about the RDBMS and version that you are working with, as any given answer may vary substantially depending upon the vendor.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement