SQL SERVER 匯入EXCEL的儲存過程

2021-08-25 17:09:56 字數 1551 閱讀 6218

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'

asbegin

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

PLSQL Developer匯入Excel資料

lsql developer匯入excel資料 最近處理將excel資料匯入oracle的工作比較多。之前都是採用sqlldr命令列匯入的方式處理。每次匯入不同格式的excel表資料,都需要先把excel檔案由 xls 格式轉換為 csv 格式,再手工根據excel檔案建立對應得資料表,然後再修改 ...

PHP tp6 exce匯入匯出

安裝 composer require phpoffice phpspreadsheet 2.建立封裝類 excel.php 封裝方法如下 根據自己的檔案位置更改命名空間 namespace use phpoffice phpspreadsheet cell coordinate use phpof...

Sqlserver匯入資料

錯誤 0xc002f210 準備 sql 任務 1 執行查詢 truncate table dbo city 失敗,錯誤如下 無法截斷表 dbo.city 因為該錶正由foreign key 約束引用。失敗的原因可能有 查詢本身有問題 未正確設定 resultset 屬性 未正確設定引數或未正確建立...