22,206
社区成员
发帖
与我相关
我的任务
分享
-- textcopy.exe 可以在 SQL Server 2000 安装光盘或安装目录找到,将文件复制到系统目录或设置环境变量
——大力——CSDN——
CREATE PROCEDURE p_txtcopy
(
@server varchar(256) = null, --> 服务器:默认为当前服务器当前实例
@login varchar(256) = null, --> 用户名:默认为信任连接
@password varchar(256) = null, --> 密码
@database varchar(256) = null, --> 数据库:默认为当前数据库
@table varchar(256), --> 表名
@column varchar(256), --> 存储文件二进制流的字段名
@file varchar(256), --> 路径和文件名
@where varchar(255), --> 条件从句:where ?=? [ and ...]
@io varchar --> 方向I/O:I存储到数据库 O从数据库读出存为文件
)
AS
SET NOCOUNT ON
declare @SQL varchar(1000)
set @SQL = 'textcopy' +
' /S"' + isnull(@server, @@servername) + '"' +
' /U ' + isnull(@login, '') +
' /P ' + isnull(@password, '') +
' /D ' + isnull(@database, db_name()) +
' /T ' + @table +
' /C ' + @column +
' /W "' + @where + '"'+
' /F "' + @file + '"' +
' /' + @io
exec master..xp_cmdshell @SQL
/*
-- 创建测试表
create table textcopy_test(id int, bin image)
-- 初始化数据
insert textcopy_test select id=1, bin=0x
-- 将 d:\test.jpg 保存到 textcopy_test
exec p_txtcopy @table='textcopy_test', @column='bin', @file='d:\test.jpg', @where='where id=1', @io='I'
-- 将二进制流读出保存为 d:\test1.jpg
exec p_txtcopy @table='textcopy_test', @column='bin', @file='d:\test1.jpg', @where='where id=1', @io='O'
-- 删除测试
drop table textcopy_test
*/
SET NOCOUNT OFF