Editing a column of text data type

  • I have  a database table and one of its column is called case_Details of data type text. I need to modify the content of this column for one of the record.

     

    I have 1200 records and the table has an identity column(ID1) and I need to modify the content of the row#954(which is called ID1).

     

    How can I do this.

     

    Thanks.

  • What exactly you did not understand in BOL article "UPDATETEXT"?

    _____________
    Code for TallyGenerator

  • UPDATETEXT will update the part of the text but I want something different.

    say my text column has a string 'abcdefghijklmnopqrstuvwxyz'

    I need  add 'STIRNGCHANGE' in place of 'fgh' of the original string.

    So modified string(of data type text) should be like this.

     

    'abcdeSTIRNGCHANGEijklmnopqrstuvwxyz'

     

    Thanks.

  • Actually updatetext does just that "exactly"

    declare @startIndex int, @patlength int, @prtval varbinary(16)

    set @patLength = 3 --len('fgh')

     

    SELECT @prtval  = TEXTPTR(case_Details) , @startIndex  = PATINDEX('%fgh%', case_Details)

    FROM yourtable

    WHERE pk_id = 1234  -- Use your primary key

         and PATINDEX('%fgh%', case_Details) > 0  -- make sure it exists

    if @@rowcount = 1

     updatetext yourtable.case_Details, @prtval  @startIndex  @patLength 'STIRNGCHANGE'

    good luck

     


    * Noel

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

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