If this is a one-time (or rare) thing, you can try to write data from the SSMS wizard, as described here:
http://sqlblog.com/blogs/eric_johnson/archive/2010/03/08/script-data-in-sql-server-2008.aspx
Or, if you need to do this often and want to automate it, you can try the SQL # library (which I wrote, and in most cases it is free, the function that you need here is not). The function for this is DB_DumpData, and also generates INSERT statements. The library can be found at: http://www.SQLsharp.com/ .
But then again, if this is a one-time or infrequent task, try the data export wizard built into Management Studio. This should allow you to create an SQL script that you can run in Production. I just checked this on a table with a VARBINARY (MAX) field containing 3,365,964 bytes of data, and the Generate Scripts wizard generated an INSERT statement with the entire hexadecimal string of 6.73 million characters for this single value.
EDIT:
Another quick and easy way to do this is so that you can copy / paste the entire INSERT statement into the SQL script and not have to worry about the BCP or the SSMS export wizard just need to convert the value to XML. You must first convert VARBINARY to VARCHAR (MAX) using the optional β1β style, which gives you a hexadecimal string starting with β0xβ. Once you have a hexadecimal string of binary data, you can combine this into an INSERT statement, and this whole thing, being converted to XML, can contain the entire VARBINARY field. See the following example:
DECLARE @Binary VARBINARY(MAX) = CONVERT(VARBINARY(MAX), REPLICATE( CONVERT(NVARCHAR(MAX), 'test string'), 100000) ) SELECT 'INSERT INTO dbo.TableName (ColumnName) VALUES ('+ CONVERT(VARCHAR(MAX), @Binary, 1) + ')' AS [Insert] FOR XML RAW
Solomon rutzky
source share