Tuesday, March 27, 2012

Copy Image data type from one table to another

Hi,
I've a column col1 of image data type in table1. I would like to copy the data from col1 to another image column col2 in table2. Before moving the value, checking has to be done to specify which col1 data from table1 is needed and the destination has to be checked too.

Example: insert into col2
(select col1 from table1 where table1_id =5)
where table2_id =6

Hence bcp wouldn't work. Can anyone suggest me a way to do it. I tried using writetext but then, i've to get data from col1 in a variable, which is not possible. Any suggestions would be very helpful.

Thanks in advance.
Ramya.I found the way to do it. Here is the code:

declare @.ptrvalsource binary(16)

DECLARE @.ptrvaldest binary(16)

select @.ptrvalsource =textptr(col1) from table1 where table1_id = 5

SELECT @.ptrvaldest = TEXTPTR(col2) FROM table2 where table2_id=6

updateTEXT table2.col2 @.ptrvaldest 0 null table1.col1 @.ptrvalsource

Thanks,
Ramya.

No comments:

Post a Comment