sql server导出excel步骤
来源:互联网 发布:ip网络计算 编辑:程序博客网 时间:2024/06/01 07:18
--1.开启全限
sp_configure 'show advanced options',1
reconfigure
go
sp_configure 'xp_cmdshell',1
reconfigure
Go
可先通过exec sp_configure权限配置
--2.如果导出到共享文件夹,请添加信任链接(一般项目中是导出到共享文件夹),如果是导出数据库本地,则直接进行第3步
exec xp_cmdshell 'net use \\192.168.88.254\work_down_excel_zip "tykj66TYKJ" /USER:administrator'
exec xp_cmdshell 'net use \\共享文件夹ip "密码" /USER:用户名'
--3.导出到共享文件夹,例如:\\192.168.88.254\work_down_excel_zip\dept20170215.xls。注意一个细节,下面的命令不能有换行
exec master..xp_cmdshell 'bcp "select * from [CTY_MS].[DBO].DataRecordTaskInfo" queryout "\\192.168.88.254\work_down_excel_zip\dept20170215.xls" -c -T -U "sa" -P "tykj66TYKJ"'
sp_configure 'show advanced options',1
reconfigure
go
sp_configure 'xp_cmdshell',1
reconfigure
Go
可先通过exec sp_configure权限配置
--2.如果导出到共享文件夹,请添加信任链接(一般项目中是导出到共享文件夹),如果是导出数据库本地,则直接进行第3步
exec xp_cmdshell 'net use \\192.168.88.254\work_down_excel_zip "tykj66TYKJ" /USER:administrator'
exec xp_cmdshell 'net use \\共享文件夹ip "密码" /USER:用户名'
--3.导出到共享文件夹,例如:\\192.168.88.254\work_down_excel_zip\dept20170215.xls。注意一个细节,下面的命令不能有换行
exec master..xp_cmdshell 'bcp "select * from [CTY_MS].[DBO].DataRecordTaskInfo" queryout "\\192.168.88.254\work_down_excel_zip\dept20170215.xls" -c -T -U "sa" -P "tykj66TYKJ"'
'bcp "select查询出来的内容" queryout "\\远程共享文件夹\dept20170215.xls" -c -T -U "数据库连接用户" -P "数据库连接密码"'
--4.步骤3的命令,可以改写为下面命令,可以在导出excel时,加上表头。表头即为''用户ID'',''用户名'',''生日'',''地址'',''电话'',应该与要导出的数据个数一直,且类型一致。
exec master..xp_cmdshell 'bcp "select ''用户ID'',''用户名'',''生日'',''地址'',''电话'' union all select convert(varchar(20),[userid]),convert(varchar(20),[username]),convert(varchar(20),[registertime]),convert(varchar(20),[listprice]),convert(varchar(20),[tel]) FROM [Test].[dbo].[User_test]" queryout "d:\dept20170215.xls" -c -T '
0 0
- sql server导出excel步骤
- Excel 导入 SQL Server 步骤:
- SQL Server 导出 excel表
- Sql Server导入导出Excel
- Sql Server 导入导出Excel
- sql server 带列名导出至excel
- sql server 带列名导出至excel
- sql server导出数据到Excel
- SQL Server导出EXCEL的存储过程
- 使用SQL Server导入/导出Excel
- 从sql server中导入/导出 excel
- sql server数据库表导出Excel
- sql server 2005导出到excel
- SQL Server导入导出excel
- excel数据导入导出SQL Server 2005
- Excel + SQL Server 导入导出类
- SQL Server导入导出excel及常见问题
- sql server 表结构 导出 到excel
- CoordinatorLayoutt +SwipeRefresh实现刷新加载多标签的咨询页
- android 和 ios中实现类似C#的BackgroundWorker接口
- Java LinkedHashSet
- OpenCV 图像分离颜色通道 split函数和mege函数的运用
- 【Codeforces-402D】-String Game (二分)
- sql server导出excel步骤
- 安装Hive On Spark 遇见的问题
- 后缀表达式的求值的算法
- [C++]什么是句柄?为什么会有句柄?
- LeetCode
- 11-12 标准IO之feof,ferror,clearerr
- 9. Palindrome Number
- 解决 Windows instance 时间不同步问题
- 漫步数学分析二十三——级数的积分与微分