Wednesday, November 4, 2009

Concatenating string data to a text column in the table

If there is any need to update the text column in SQL table with some varchar data, the following tip might come be handy.

For example, if you have a column 'Description' which is defined as a TEXT filed in the table and you want to concatenate "Test Description" to the already existing data in the column, we CANNOT do it directly. Here is how to convert a TEXT column into a VARCHAR and then append data to it.

UPDATE table_name
SET Description = Convert(VARCHAR, Description) + "Test Description"

NOTE : Do not forget to filter rows based on a WHERE condition above, else all the rows in the table will be updated.

No comments:

Post a Comment