SET @PATH = ' textcopy/s ' + @LServer +
'/u ' + @LUser +
'/P ' + @LPass +
'/d ' + @LDB +
'/T '[email protected]+
'/C ' [email protected]+
'/w '[email protected]
'/F ' + @LPath + ' \ ' + @File + '/o '
EXEC Master. xp_cmdshell @Path
/** description
@LServer: Server name
@LUser: User Name
@LPass: Password
@LDB: Database
@table: Table Name
@column: Column Name
@Lwhere: Query criteria
@LPath: Path
@File: File name
***/
An example of success:
DECLARE @where varchar (200)
DECLARE @file varchar (500)
DECLARE @PATH varchar (DECLARE) @id int, @stockcode varchar, @stocksname varchar, @declaredate datetime, @F001 varchar (20)
DECLARE SP cursor Forselect id,stockcode,stocksname,declaredate,f001
From T1open Spfetch next from SP into @id, @stockcode, @stocksname, @declaredate, @F001while (@ @fetch_status =0)
Begin
Set @where = ' where id= ' +convert (varchar), @id) + ' "'
Set @file = ' ('[email protected]+ ') '[email protected]+ ' (' +convert (char (8), @declaredate, () + ') '[ Email protected]+ '. txt 'SET @PATH = ' textcopy/s yubaolong\s2 ' +
'/u ' + ' sa ' +
'/P ' + ' 123 ' +
'/d ' + ' DB40 ' +
'/T ' + ' t1 ' +
'/C ' + ' F002 ' +
'/w'[email protected]+ '/F ' + ' d:\111 ' + ' \ ' [email protected]+ '/o '--' '/' + ' + ' + ' F:\PDF\11.PDF ' + '/o '
EXEC Master. xp_cmdshell @Path
FETCH NEXT from SP into @id, @stockcode, @stocksname, @declaredate, @F001
Endclose Spdeallocate SP
-------------------------------------------------------------------
SQL Server calls Textcopy write file