How to add string to ntext column

  • Hi ,

    The wrong way :

    UPDATE Customer SET CustText = CustText + 'ABCD'

    WHERE CustId = 10

    The right way :

    ?

     

    The error message :

    Invalid operator for data type. Operator equals add, type equals ntext.

  • try this

    UPDATE Customer SET CustText = cast(CustText as varchar(8000)) + 'ABCD'

    WHERE CustId = 10

    cheers

    Rajesh

     

  • But what if CustText contains more then 8000 ?

  • I think there is no other way since SQL server doesn't allow to concatinate nText , image etc datatypes. Don't know if there is any other work around if it exceeds 8000 characters.

    cheers

    Rajesh

     

  • OK

    Thanks Rajesh

  • try this one ...

    DECLARE @ptrval binary(16)

    SELECT @ptrval = TEXTPTR(CustText)

       FROM customer WHERE CustId = 10

    UPDATETEXT Customer.CustText @ptrval  null null  'ABCD'

    GO

    for more info have a look at UPDATETEXT in BOL

    Cheers

    Rajesh

     

Viewing 6 posts - 1 through 5 (of 5 total)

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