Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Appending two strings in SQL

Posted on 2006-10-30
5
Medium Priority
?
8,721 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 500 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
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.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

971 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