sqlServer海量数据导出为Excel

---1、开启xp_cmdshell选项;基于安全的考虑,系统默认没有开启xp_cmdshell选项

EXEC sp_configure 'show advanced options', 1;

RECONFIGURE;

GO

EXEC sp_configure 'xp_cmdshell', 1;

RECONFIGURE;

GO

---2、查询服务名

SELECT serverproperty('servername')

---3、导出表至EXCEL(类Excel,虽然格式是xls,但不受行数限制,且为只读,若修改需另存为Excel)

EXEC master..xp_cmdshell 'bcp 数据库.dbo.表 out c:\Temp.xls -c -q -S"服务名" -U"用户名" -P"密码"'

---示例

--EXEC master..xp_cmdshell 'bcp "select ''月份'',''编码'',''名称'',''住院号'',''姓名'',''生日'',''入院日期'' union all select convert(varchar(20),month,120) ,code ,name,hospital_no ,person_name ,convert(varchar(20),birthday,120),convert(varchar(20),in_date,120) from drgsdb_ggrm.dbo.drg_record" queryout c:\病案数据.xls -c -q -S"YCW-PC" -U"sa" -P"system"'

---4、关闭sp_cmdshell选项

EXEC sp_configure 'show advanced options', 1

RECONFIGURE;

GO

EXEC sp_configure 'xp_cmdshell', 0

RECONFIGURE;

GO

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值