Solved

Appending two strings in SQL

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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

685 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