Solved

Appending two strings in SQL

Posted on 2006-10-30
5
8,711 Views
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.

thanks,
0
Comment
Question by:expertsit
  • 2
  • 2
5 Comments
 
LVL 143

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?
0
 

Author Comment

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

thanks,
0
 
LVL 5

Accepted Solution

by:
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.
0
 

Author Comment

by:expertsit
ID: 17837765
Thanks. That worked.
0
 
LVL 143

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...
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

860 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