Managing Text, Image in Stored Proc on MSSQL

Hello

I have a problem when I'm copying data in a table with a column which is
TEXT. I have another table which has a column IMAGE where similar code
works fine. Here is the code that doesn't work:

-----------------------------
DECLARE #CopyResCur CURSOR FORWARD_ONLY FOR

  SELECT NotePage, Departments, LISTS, TEXTPTR(Text), DATALENGTH (Text)
  FROM ReservationNotes (NOLOCK) WHERE ReferenceNumber=@OldReferenceNumber
AND GuestNumber=@OldGuestNumber

OPEN #CopyResCur

FETCH NEXT FROM #CopyResCur
INTO @NotePage, @Departments, @LISTS, @FromText, @Length

WHILE (@@FETCH_STATUS <> -1)
BEGIN
  INSERT INTO ReservationNotes (ReferenceNumber, GuestNumber, NotePage,
Departments, LISTS)
  VALUES (@NewReferenceNumber, @NewGuestNumber, @NotePage, @Departments,
@LISTS)

  IF @Length > 0
  BEGIN
    SELECT @ToText = TEXTPTR(Text) FROM ReservationNotes (NOLOCK) WHERE
ReferenceNumber=@NewReferenceNumber AND GuestNumber=@NewGuestNumber AND
NotePage=@NotePage  -- GET pointer to blob in new record

    IF (TEXTVALID ( 'ReservationNotes.Text' , @FromText) = 1) AND
(TEXTVALID ( 'ReservationNotes.Text' , @ToText) = 1)
      WRITETEXT ReservationNotes.Text @ToText @FromText  -- write data from
blob to new blob
  END

  FETCH NEXT FROM #CopyResCur
  INTO @NotePage, @Departments, @LISTS, @FromText, @Length
END

CLOSE #CopyResCur
DEALLOCATE #CopyResCur
-----------------------------

If I remove the line where I check if TEXTVALID I will get the following
error:

"NULL textptr (text, ntext, or image pointer) passed to WriteText
function".

Neither should be null!?

What the code does is read with a cursor some rows. Then it inserts these
rows with new keys into the same table. Then it get a pointer to the TEXT
field of the new record and then it writes to write the content of what
from pointer points to, to the to pointer.
I think the problem is that the to pointer somehow is null, but I cannot
figure out why.

I hope someone can help. As I said the code works on a table with a Image
column (no I cannot change this text col to a image col :))

--
Jacob Pedersen
AK Techotel
J.Peder...@nospamtechotel.dk
(Remove nospam when replying!)