请教:SQL2008中image字段内容如何导出成文件
黑色水墨 2015-09-12 04:23:07 数据库为SQL200R2,
create table tb(id int,img image)
insert tb
SELECT 1, * FROM OPENROWSET(BULK N'E:\ABC.xls', SINGLE_BLOB) AS Document
insert tb
SELECT 2, * FROM OPENROWSET(BULK N'E:\EFG.jpg', SINGLE_BLOB) AS Document
我将两个文件存入到数据表 tb中,现在我想把表tb中字段img存放的文件取出来,只通过SQL语句即SQL端实现该功能,
通过这样的方式导出文件:
sp_configure 'show advanced options',1
reconfigure
go
sp_configure 'xp_cmdshell',1
reconfigure
go
EXEC master..xp_cmdshell 'bcp "select img from Text..tb Where id=1 " queryout "e:\test.xls" -c -x -S"(local)" -U"sa" -P"123456" '
EXEC master..xp_cmdshell 'bcp "select img from Text..tb where id=2 " queryout "e:\test.jpg" -c -x -S"(local)" -U"sa" -P"123456" '
但是这样导出的文件无效,图片打开无内容,Excel打开发现只是将image中存放的二进制值放入到A1单元格中。
请教各位,有什么方法能在SQL中将image类型字段中存放的文件再导出成文件且文件正常?