小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

數(shù)據(jù)導(dǎo)入(存儲過程讀取excel)

 jilicheng 2014-02-13

適用CIIS,CMIS,ZYT,ECRM

數(shù)據(jù)導(dǎo)入(存儲過程讀取excel)

功能: 可更新原來數(shù)據(jù)庫已經(jīng)存在的數(shù)據(jù),然后插入新數(shù)據(jù).

原理: 直接從上傳的excel表中讀取,存入臨時(shí)表,更新數(shù)據(jù)庫表中與臨時(shí)表中相同主鍵字段的數(shù)據(jù),再刪除臨時(shí)表中在數(shù)據(jù)庫表中已經(jīng)存在的記錄,再插入臨時(shí)表剩余的新數(shù)據(jù).

來源:同事.

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO


--=======================================================
/*
funciton:補(bǔ)貼扣除導(dǎo)入
coder:zx
datetime:2009-10-14

[P_Import_Transportation] 0,'\\192.168.0.2\hglwpqvss\uploadFile\月度崗位補(bǔ)貼扣除表20091022150944_20091022031241.xls','2009-10-01','35242100'

*/
--=======================================================
ALTER proc [dbo].[P_Import_Transportation]
@UserID     int,      --操作人
@FilePath    varchar(1000),    --文件路徑
@DataTime    datetime,     --數(shù)據(jù)月份
@OrganizationalNum2 varchar(50),    --二級單位
@rc      int=null output,
@info     varchar(100)=null output
as
begin
declare @WONum varchar(50)
select @WONum=WorkOrderNum from T_E_WorkOrder where and and AATID=18
if(@WONum is null)
begin
   set @rc=-1
   set @info='工單未建立'
   return
end

declare @Count_Employee int,@Count_Excel int,@SQL varchar(8000),@Add int,@Update int

create table #Temp_TableAD
(序號      int identity(1,1),
三級部門     varchar(200),
Mis員工編號     varchar(50),
-- 員工編號     varchar(50),
員工姓名     varchar(50),
補(bǔ)貼交通費(fèi)員工類型   varchar(50),
交通費(fèi)      decimal(18,2))

set @SQL='insert into #Temp_TableAD(三級部門,Mis員工編號,員工姓名,補(bǔ)貼交通費(fèi)員工類型,交通費(fèi))'+
          'select 三級部門,Mis員工編號,員工姓名,補(bǔ)貼交通費(fèi)員工類型,isnull(交通費(fèi),0),'+
          ' from OpenDataSource( ''Microsoft.Jet.OLEDB.4.0'','+'''Excel 8.0; HDR=Yes; IMEX=1;'+
          'Data ID=;Password=;'')...[交通費(fèi)信息$] WHERE isnull(員工編號,'''') <> '''''  
print @SQL

exec(@SQL)
-- select * from #Temp_TableAD
--模板數(shù)據(jù)邏輯驗(yàn)證
if exists(select 1 from #Temp_TableAD group by 員工編號 having(count(1)>1))
begin
   set @rc = -1
   set @info='數(shù)據(jù)錯(cuò)誤,出現(xiàn)重復(fù)員工編號'
   return
end

--二級單位本月份在職員工數(shù)
-- select @Count_Employee=count(1)
-- from T_E_Employee a
-- inner join T_H_EmployeeAttribution b on a.EmployeeNum=b.EmployeeNum and
-- where and a.DataState=1
--
-- --Excel中員工數(shù)
-- select @Count_Excel=count(1) from #Temp_TableAD

--print @Count_Employee
--print @Count_Excel
-- --員工數(shù)驗(yàn)證
-- if(@Count_Employee > @Count_Excel)
-- begin
--   set @rc = -2
--   set @info='存在未導(dǎo)入的員工'
--   return
-- end

/*數(shù)據(jù)導(dǎo)入*/  
--更新已有數(shù)據(jù)
update T_E_EmployeeTransportation
set
   Transportation = 交通費(fèi),
   PTTYPE=補(bǔ)貼交通費(fèi)員工類型
from T_E_EmployeeAllowanceDeduction a ,#Temp_TableAD
where a.MisEmployeeNum = Mis員工編號 and

set @Update=@@rowcount

--刪除已更新數(shù)據(jù)
delete #Temp_TableAD
from T_E_EmployeeTransportation a ,#Temp_TableAD
where a.MisEmployeeNum = Mis員工編號 and

--新增數(shù)據(jù)
insert into dbo.T_E_EmployeeTransportation(DataTime,MisEmployeeNum,PTType,Transportation,OrganizationalNum2,WONum)
select @DataTime,Mis員工編號,補(bǔ)貼交通費(fèi)員工類型,交通費(fèi),@OrganizationalNum2,@WONum from #Temp_TableAD
set @Add=@@rowcount

set @rc=1
set @info='共導(dǎo)入 '+cast(@Add+@Update as varchar)+' 條數(shù)據(jù),其中 ' + cast(@Update as varchar) + ' 條更新; ' + cast(@Add as varchar) + ' 條新增'
print @info
end

    本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多