日期:2014-05-19  浏览次数:20437 次

sql存储过程,记录日志到txt
在sql存储过程,记录日志到txt
sql直接写到txt是可以这样的:
exec   master..xp_cmdshell   'bcp   "select   *   from   temp_em..temp_perf "   queryout   "d:\tt.txt "   -c   -S.   -Usa   -Ppwd '

但是因为记录日志,不能重写tt.txt,而是不断加上去,请问该怎么解决?

------解决方案--------------------
exec master..xp_cmdshell 'bcp "select * from temp_em..temp_perf " queryout "d:\tt "+convert(char(10),getdate(),21)+ ".txt " -c -S. -Usa -Ppwd ' ---文件名变成加上日期的
------解决方案--------------------
如果temp_em..temp_perf中的记录是所有的
那么导出前先删除d:\tt.txt
再exec master..xp_cmdshell 'bcp "select * from temp_em..temp_perf " queryout "d:\tt.txt " -c -S. -Usa -Ppwd '