cancel
Showing results for 
Search instead for 
Did you mean: 

Export long binary field to text file?

10-18-2017 1:10 PM
4877 views 5 comments Go to solution
0 Likes
SAP Managed Tags
Subscribe

I try to export long binary field to text file and insert into to another database, but the export of the long binary will not be correct. I'm writing this way:

SELECT long_binary_filed from testtable;
output to 'c:\\temp\\Test1.txt' ENCODING 'utf-8';

What I'm wondering is how I can export long binary fields to a text file so I can add it to another database then with an insert?

0 Likes

Accepted Solutions (1)

Accepted Solutions (1)

MarkCulp
Participant

I suggest that you use xp_write_file() since it will not try to do any character conversion on the binary blob when it writes it to the file.

Former Member
0 Likes

Okay, thanks for the quick reply. If I then export this.

SELECT xp_write_file( 'c:\\temp\\Test1.txt', long_binary_filed ) FROM testtable;

Do I then read it with xp_read_file? How?

MarkCulp
Participant
0 Likes

Yes, one way to read the file would be to use xp_read_file.

begin
  declare @blob long binary;
  set @blob = xp_read_file( 'c:\\temp\\Test1.txt' );
  ...
end;
Former Member
0 Likes

Then I do an insert (or update) like this?

INSERT INTO testtable ( long_binary_field ) VALUES ( xp_read_file( 'c:\\temp\\Test1.txt' ) );
MarkCulp
Participant
0 Likes

Yes, that should work.

Answers (0)