Hi, I am trying to insert and export a binary file into SQL 2005. I need that word, pdf and txt file work.
I can't use file path and this is the only choice I have.
I am using this way:
1) Create a file test.txt and write "hello" into it.
2) CREATE TABLE [dbo].[myfiles]( [file] [varbinary](max) NOT NULL) ON
3) INSERT INTO [myfiles]([file])
FROM OPENROWSET (
SINGLE_BLOB) AS BinFile
4) declare @SQLcommand nvarchar(4000)
set @SQLcommand = 'bcp "SELECT top 1 [file] FROM myfiles" queryout "c:
\temp\test.txt" -T -n -SMYPC'
exec xp_cmdshell @SQLcommand
When I open file c:\temp\test.txt I can see strange characters before "hello"
Trying to insert a word file says me that the file is corrupted.
How can I solve this ?
View Complete Post