怎样利用BCP将数据表导出到某个文本文件不删除原来该文本文件的数据?

ufo_ufo 2004-12-14 04:11:36
?
...全文
180 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
LBYYBL 2004-12-14
  • 打赏
  • 举报
回复
想到两个方法:
1.把n个查询结果select 到一个临时表里,再统一导出到d:\test.txt
select * into table1 from t1 where ...
union all
select * from t2 where ...
union all
select * from t3 where ...

go
EXEC master..xp_cmdshell 'bcp temp..table1 out d:\test.txt -c -S"Servername" -U"sa" -P"sa"'
2.导成n个txt文件,在追加到一个里面
EXEC master..xp_cmdshell 'bcp temp..table1 out d:\test1.txt -c -S"Servername" -U"sa" -P"sa"'
EXEC master..xp_cmdshell 'bcp temp..table2 out d:\test2.txt -c -S"Servername" -U"sa" -P"sa"'

--再用下面语句将test1.txt,test2.txt合起来到test1.txt里面
exec xp_cmdshell'copy /Y d:\test1.txt+d:\test2.txt d:\test1.txt'
ufo_ufo 2004-12-14
  • 打赏
  • 举报
回复
就是几个查询出来的结果都要放在一个文本文件中
LBYYBL 2004-12-14
  • 打赏
  • 举报
回复
追加就不会了,楼主有什么要求,倒成几个在合起来不行么
EXEC master..xp_cmdshell 'bcp temp..table1 out d:\test.txt -c -S"Servername" -U"sa" -P"sa"'
火山企鹅 2004-12-14
  • 打赏
  • 举报
回复
BCP是什么?
你做个文件追加不就ok?

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧