--将test_1表导出在F盘根目录下/

reconfigure
EXEC master..xp_cmdshell 'bcp test.dbo.test_1 out f:\abc.txt -c -q -U"sa" -P"123456"'

--同上

EXEC master..xp_cmdshell 'bcp test.dbo.T out D:\Temp.xls -c -q -S "MICROSO-B9HH53O" -U "sa" -P "123456"'

--同上

EXEC master..xp_cmdshell 'bcp test.dbo.T  out  f:\abc.xls -c -q -T'

经测试:-U -P 必须大写。

--由于导出是没有列名的需要手工复制表结构
select * into a from test_1 where 1=2
 
导入
然后 将OUT 改成IN即可。
 
--当我们要输出具体的数据时,输出参数改为QUERYOUT其中-F 4 -L 7 是指从所查出来的结果中取第4条到7条记录进行导出(一共4行),这样就避免了子查询倒序排列啥啥啥的。分页的搞法,太过麻烦。

EXEC master..xp_cmdshell 'BCP "SELECT TOP 7 * FROM newname.dbo.AA_BB" queryout c:\abc.xls -F 4 -L 7 -c -U"sa" -P"123456"'

 
MSsql bcp

 

 

 

相关文章:

  • 2021-08-05
  • 2021-12-13
  • 2021-05-31
  • 2021-11-05
  • 2021-10-04
  • 2021-10-16
  • 2021-12-12
  • 2021-08-04
猜你喜欢
  • 2021-08-01
  • 2022-03-06
  • 2021-04-06
  • 2021-07-14
  • 2022-12-23
相关资源
相似解决方案