set @sql='bcp "'+@tbname
+case when @isout=1 then '" out' else '" in' end
+' "'+@filename+'" /c' +' /S"'+@servername
+case when isnull(@username,'')='' then ''
else '" /U"'+@username end
+'" /P"'+isnull(@password,'')+'"'
+' /t"'+@fdsplit+'"'
+' /r"'+@rowsplit+'"'
cmdtxt:='bcp "SELECT * FROM b " queryout c:\Authors.txt -c -S localhost -U sa -P ';
// SELECT * FROM b 可以是任何可以获得记录集的脚本
// c:\Authors.tx 输出文件
//数据库
//sa 用户
//-p后面是密码
with tstringlist.Create do
begin
add(cmdtxt);
savetofile('a.bat');
free;
end;
winexec('a.bat',0);
deletefile('a.bat');