Copying an ntext cell from one cell into another (destination row already exists)

  • Hi!

    What I'd like to do is:

    UPDATE table1

    SET

    A_TEXT_COLUMN = (SELECT another_text_column

    FROM table2

    WHERE table2_id = @precomputed_id_1)

    WHERE table1_ID = @precomputed_id_2

    Since the cells are text, this does not work. Since the cell to be updated

    is in an already exitant row, it's not possible to simply use insert.

    I'd like to do something like (PSEUDOcode):

    WRITETEXT(table1.A_TEXT_COLUMN,

    READTEXT(@textptr_initialised_to_point_at_target_cell))

    But the *actual* synatx of WRITETEXT and READTEXT seem totally inappropriate

    for any such trick...

    Any hints or pointers HUGELY appreciated... THANX

  • Is this a standard *problem*? Or an unsolved one (just an sqlserver limitation that must be dealt with in a totally different way??)

    I saw 10 people read the thread but nobody answered, maybe the problem is a generally troublesome one with no good solutions...

    Any ideas at all?

    Thanx,

    wOAst

  • Is this what you want? 

    declare @source_ptr binary(16), @target_ptr binary(16), @id1 int, @id2 int

    select

    @source_ptr = textptr(col1) from tbl1 where id = @id1

    select @target_ptr = textptr(col2) from tbl2 where id = @id2

    update

    tbl2 set col2 = 'a' where id = @id2 --to ensure there's something there

    updatetext

    tbl2.col2 @target_ptr 0 null tbl1.col1 @source_ptr

     

     

  • excellent!

    thanx!

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

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