Appending two strings in SQL

Posted on 2006-10-30
Last Modified: 2008-02-26
I would like to update a column in a table with a string. Later on I would like to add to that string.

I tried the following query,

"update TABLE1 set COLUMN1 = COLUMN1 + 'TEST STRING'  where ID = 100"

I get this error, "Invalid operator for data type. Operator equals add, type equals text."

The 'COLUMN1' is of type text.

Any help is appreciated.

Question by:expertsit
  • 2
  • 2
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17837229
>The 'COLUMN1' is of type text.

do you need to have TEXT as data type?
is varchar(8000)   in sql server 2000 resp varchar(max) in sql server 2005 not enough?

Author Comment

ID: 17837553
I cannot change the design of the table. I dont have rights. Is it not possible to add two text fields?


Accepted Solution

CIC Admin earned 125 total points
ID: 17837733
Try converting the text column to a varchar first, then add your text to that varchar like so:

update TABLE1 set COLUMN1 = cast(COLUMN1 as varchar(8000)) + 'TEST STRING'  where ID = 100

You may also want to check out the UPDATETEXT command in BOL or in other PAQ's here.

Author Comment

ID: 17837765
Thanks. That worked.
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17839959
>Is it not possible to add two text fields?
as shown it is possible, but you will only get up to 8000 characters in that field. if you try to store more, it will get truncated...

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Query Optimization 14 45
SQL Insert parts by customer 12 34
Query Help - MSSQL - Averages 5 27
transaction in, sql server 6 33
I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question