当前位置: 代码迷 >> Sql Server >> sql 2008 bcp出的XLSX文件多了换行,导致文件打开异常,怎么处理
  详细解决方案

sql 2008 bcp出的XLSX文件多了换行,导致文件打开异常,怎么处理

热度:21   发布时间:2016-04-24 10:32:00.0
sql 2008 bcp出的XLSX文件多了换行,导致文件打开错误,怎么办?
情况是这样的:
远程将XLSX文件以二进制形式导入sql某一字段,然后在sql 2008 中用bcp方式还原到本地,结果发现xlsx打开错误,比原来的文件大了几个字节(好象多了0D0A),试了txt、xls类型文件,也大,但打开正常。怎样在sql环境中把多余的字节去掉??
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
EXEC sp_configure 'xp_cmdshell', 1
RECONFIGURE
EXEC sp_configure 'show advanced options', 0
RECONFIGURE
EXEC master..xp_cmdshell 'if not exist D:\sqlxls1 (md D:\sqlxls1)'--新建文件夹
declare @f nvarchar(255),@f1 varchar(max)
set @f='D:\sqlxls1\' + @xname
declare @sql nvarchar(255)
set @sql='BCP "select cast(substring(imgfield,1,datalength(imgfield)) as varchar(max)) FROM Northwind.dbo.MyImages" queryout '+@f+'  -T -c -q '---r\0  --行终止符
EXEC master..xp_cmdshell @sql
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
EXEC sp_configure 'xp_cmdshell', 0
RECONFIGURE
EXEC sp_configure 'show advanced options', 0
RECONFIGURE

------解决方案--------------------
文件以二进制存储最好用前端程序来完成喔,毕竟用户的读写都是离不开程序的.
用SQL不太专业.
  相关解决方案