How to copy blob (binary data) from one DB to DB using a script? We are trying to copy a blob (binary data) from one Database to another Database using a simple script. This is the steps we do.


Select the value using MSSQL Studio Client.
Copy it into the clipboard.
Paste it into anINSERT script using notepad.
Apply it into the destination database.


We notice that the value is now an ASCII that starts with 0x255.... which seems to be the hexadecimal representation of the binary data. Is there a way we can convert it back to binary during the insert?

Is there a better way to copy blob data using scripts? Assume, we don't have direct connection to destination Database.
I would use the "Generate Scripts" option in SQL Server Management Studio.


In Object Explorer - highlight the database hosting the source
table.
Right-click menu - Tasks | Generate Scripts 
Select specific table object - click Next page
Click Advanced button
Under General Options
    - Change 'Type of data to script' to "Data Only"
Save to file - change folder and filename as required.


I tried a simple test with a table storing a varbinary field.  The output from the Scripting process looked ok:

USE [TestDB]
GO
/****** Object:  Table [dbo].[tjc_blob]    Script Date: 07/04/2017 14:46:23 ******/
INSERT [dbo].[tjc_blob] ([id], [datablob])
VALUES (1, 0x6162636465666768696A6B6C6D6E6F707172737475767778797A)