views:

40

answers:

3

I have some varbinary data stored in a table in MS Sql Server 2005. Does anyone have SQL code that takes a query as input (lets say the query guarantees that a single column of varbinary is returned) and outputs the bytes to disk (one file per row?) I'm sure this has been asked a thousand times before, but Googling comes up with mostly .net solutions. I want an SQL solution.

+1  A: 

You can use BCP, not T-SQL, but works well.

BCP "SELECT FileContent FROM table WHERE ID = 1" queryout "C:\file.txt" -T
Dustin Laine
Hi Dustin - I was able to use command to output a file, but I don't think its working properly. The data is a serialized .net object. I know the data is stored properly because I have processes that operate on that data from .net. However, when I try to deserialize I get an error, which means that the bytes aren't written properly. Thoughts? If the command outputs a single varbinary(max) value, are the actual bytes written to disk or does the process include headers, etc.?
SFun28
A: 
Alberto Martinez