158.导出northwind中employees的图像

--用下面的方法导出就可以保证导出标准的图片文件

declare @id int,@fn nvarchar(260),@tmpfn nvarchar(260)
select @id=2				--要导出的employeeid
	,@fn='c:\test.bmp'		--导出生成的文件名
	,@tmpfn='c:\tmp.bak'	--导出过程中使用的临时文件名

--生成临时表,控制取消图片数据中的前缀
create table ##tb(img image)
insert into ##tb
select photo from northwind..Employees where employeeid=@id

--删除前缀处理
declare @p varbinary(16)
select @p=textptr(img) from ##tb
updatetext ##tb.img @p 0 78 null

--导出数据
declare @sql varchar(8000)
set @sql='bcp "select * from(select null as 类型 union all select 0 as 前缀 union all select 0 as 长度 union all select null as 结束 union all select null as 格式) a" queryout "'
	+@tmpfn+'" /c /S"zj" /P""'
exec master..xp_cmdshell @sql,no_output

set @sql='bcp ##tb out "'+@fn+'" /S"zj" /P"" /i"'+@tmpfn+'"'
exec master..xp_cmdshell @sql,no_output

set @sql='del '+@tmpfn
exec master..xp_cmdshell @sql,no_output
go
drop table ##tb
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值