SQL SERVER 导入EXCEL的存储过程
1.先在查询分析器里执行
exec sp_configure "show advanced options",1
reconfigure
exec sp_configure "Ad Hoc Distributed Queries",1
reconfigure
2.存储过程
ALTER procedure [dbo].[sp_ImpCustomer]
@ExcelPath varchar(1000),
@SheetName varchar(100)='Sheet1',
@ExcelField varchar(500)='帐号,姓名,机构,经纪人,区域经理,销售行政,电话',
@TableName varchar(100)='t_busi_callingcust'
as
begin
set nocount on
declare @strSql varchar(4000)
-- 打开开关
--exec sp_configure "show advanced options",1
--reconfigure
--exec sp_configure "Ad Hoc Distributed Queries",1
--reconfigure
-- 重启sql full-text filter daemon launcher,sql server俩个服务
IF EXISTS (SELECT * FROM dbo.SysObjects WHERE ID = object_id(@TableName)
AND OBJECTPROPERTY(ID, 'IsTable') = 1)
TRUNCATE TABLE t_busi_callingcust -- 删除表中的所有数据
else
-- 创建表
create table t_busi_callingcust(
Accounts varchar(20) null,
CustName varchar(50) null,
Orgazition varchar(50) null,
[Broker] varchar(50) null,
DistrictManager varchar(50) null,
SalesAdmin varchar(50) null,
Tel varchar(30) null
)
SET @ExcelPath = '''Microsoft.Jet.OLEDB.4.0'',''Data Source="' + @ExcelPath + '";User ID=Admin;Password=;Extended properties=Excel 5.0'''
SET @strSql = 'insert into ' +@TableName+' select * from opendatasource('+@ExcelPath+')...'+@SheetName+'$'
--print @strsql
EXEC(@strSql)
set nocount off
end
最新文章
- 深入浅出 Redis client/server交互流程
- js事件绑定及深入
- JAVA中的枚举小结
- [转]编译VC++程序warning C4819快速解决
- mysql服务器的字符集
- C# 模拟并发
- cdoj 1131 男神的礼物 区间dp
- tcpdump抓包分析具体解释
- 将多个Sheet导入到同一个Excel文件中
- AI - 深度学习之美十四章-概念摘要(1~7)
- [LeetCode] Number of Matching Subsequences 匹配的子序列的个数
- 微信小程序自运营器 微信小程序自动运营器(让你的微信小程序,公众号零运营成本,24小时全自动运营)
- 固态硬盘的PCIE,SATA,M2,NVMe,AHCI分别都指什么?别再搞混了
- bind注意事项(传引用参数的时候)
- ARM架构相关学习归纳总结
- 利用Linux的硬连接删除MySQL大文件
- jQuery的html和css
- 数据库同步相关的SQL语句
- AutoCAD 导入 Altium Designer 10 教程
- MySQL8 重置改root密码及开放远程访问
热门文章
- 我的PHP之旅--认识数据库及数据库操作
- oracle 内置函数 least decode
- jQuery CSS 添加/删除类名
- chr(i)	返回整数i对应的ASCII字符
- 转--Server “**” has shut down the connection prematurely一例分析
- 如何查看Linux的磁盘空间还有多少
- NEERC 2010, Eastern subregional contest
- [wikioi]均分纸牌
- 定时显示提示控件 TToolTip
- Android WebView 开发详解(三)