Update text in table column with ntext datatype

  • need help on how to update a string in a table column. I want to replace 'Brodmann-10' with 'Brodmann-1910'. The following script does not work right. I appreciate your help:)

    DECLARE @FindString varchar(80)

    DECLARE @ReplaceString varchar(80)

    SET @FindString = 'Brodmann-10'

    SET @ReplaceString = 'Broadmann-1910'

    SET NOCOUNT ON

    DECLARE @TextPointer varbinary( 16 )

    DECLARE @DeleteLength int

    DECLARE @OffSet int

    SELECT @TextPointer = textptr( Description)

    FROM Brodmann --Brodmann is a table only has 5 rows

    SET @DeleteLength = len( @FindString )

    SET @OffSet = 0

    WHILE ( SELECT count( * ) FROM Brodmann WHERE charindex( '%Brodmann-10%', Description) <> 0) > 0

    BEGIN

    SELECT @OffSet = charindex( '%Brodmann-10%', Description) -1

    FROM Brodmann

    WHERE charindex('%Brodmann-10%', Description) <> 0

    UPDATETEXT Brodmann.Description

    @TextPointer

    @OffSet

    @DeleteLength

    @ReplaceString

    END

    RETURN

  • SQL Server is not a text editor.

    It's Relational Database Management System.

    You have to choose:

    - either to store you data in proper relational database and use RDMS to manage it;

    - or keep storing it as a text file and find another, proper tool to edit it.

    _____________
    Code for TallyGenerator

  • If the length of your ntext field is under 4000 characters then cast it to a VARCHAR and use the REPLACE statement.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply