tags:

views:

528

answers:

2

How do you copy an image data type (or varbinary(max)) from one table to another in SQL Server, without having to save the data to a file first?

A: 

You can just use an insert statement with a SELECT clause, for example:

declare @t1 table (t1 image)
declare @t2 table (t2 image)
insert into @t2 select t.t1 as t2 from @t1 as t

You can get full details about the INSERT statement here:

http://msdn.microsoft.com/en-us/library/ms174335.aspx

casperOne
+2  A: 

You select the records from one table and insert into another. As you do it in the same query, the data doesn't leave the database, so you don't have to store it anywhere.

Example:

insert into SomeTable (SomeId, SomeBinaryField)
select SomeId, SomeBinaryField
from SomeOtherTable
where SomeId = 42
Guffa