Remove a  string in a text field

Posted on 2007-10-16
Last Modified: 2012-06-27
In a stored procedure, How can I remove a text string in a  text field.

Textfield = 'Something ABCSomething else'

I want to remove the 'ABC' from the text field,

so that when I am done,
Texfield =  'Something Something else'

Thanks in Advance,

Question by:misdevelopers
    LVL 16

    Expert Comment

    select replace(columnname, 'string', 'withstrng')

    Author Comment

    Thank you for the suggestion.
    When I tried it, I got:
    Argument data type text is invalid for argument 1 of replace function.

    The field is defined as a data type of text.


    LVL 15

    Accepted Solution

    The only way you can do this is to use CAST to cast the TEXT data to VARCHAR. The 'problem' is that VARCHAR is only limited to 8000 characters total, so if your text string is longer than that, you are hosed. If it is less than 8000 characters, you can do
    DECLARE @Text VARCHAR(8000)
    SET @Text


    This casts the text to varchar, does the replacement, then casts it back to text.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
    The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
    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.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now