当前位置:Gxlcms > 数据库问题 > SQL SERVER调用textcopy写文件

SQL SERVER调用textcopy写文件

时间:2021-07-01 10:21:17 帮助过:71人阅读

+

        ‘ /C ‘ +@column+

        ‘ /W ‘+@Lwhere

        ‘ /F ‘ + @LPath +‘\‘+  @File + ‘ /O‘

EXEC master..xp_cmdshell @Path

/**说明

@LServer:服务器名

@LUser:用户名 

@LPass:密码

@LDB:数据库

@table:表名

@column:列名

@Lwhere:查询条件

@LPath:路径

@File: 文件名

***/

 

 一个成功的实例 :

declare @where varchar(200)
declare @file varchar(500)
declare @PATH varchar(800) declare @id int,@stockcode  varchar(20),@stocksname varchar(20),@declaredate datetime,@F001 varchar(20)
declare sp cursor for select id,stockcode,stocksname,declaredate,f001
from  t1 open sp fetch next from sp into @id,@stockcode,@stocksname,@declaredate,@F001 while(@@fetch_status=0)
begin
set @where=‘"where id=‘+convert(varchar(20),@id)+‘"‘
set @file=‘(‘+@stockcode+‘)‘+@stocksname+‘(‘+convert(char(8),@declaredate,112)+‘)‘+@F001+‘.txt‘ SET @PATH = ‘textcopy /S yubaolong\s2‘ + 
        ‘ /U ‘+ ‘sa‘ +
        ‘ /P ‘+ ‘123‘ +
        ‘ /D ‘+ ‘db40‘+
        ‘ /T ‘+‘t1‘+
        ‘ /C ‘ +‘F002‘+
        ‘ /W ‘+@where+‘ /F ‘ + ‘d:\111‘ +‘\‘+@file+ ‘ /O‘ --        ‘" /F ‘ + ‘F:\PDF\11.PDF‘ + ‘ /O‘ 
EXEC master..xp_cmdshell @Path
 fetch next from sp into @id,@stockcode,@stocksname,@declaredate,@F001
end close sp deallocate sp

 

-------------------------------------------------------------------

SQL SERVER调用textcopy写文件

标签:status   cursor   服务   txt   master   ***   extc   查询   code   

人气教程排行