跨数据库访问数据表:

opendatasource('sqloledb', 'data source=DATABAK ;UID=sa;pwd=).数据库.dbo.表名

跨数据库访问数据表:

Create Procedure KqToDeptPersonMday
As
begin
--人事离职处理 更新人员表
declare @PersonNo as int,@Name as nvarchar(10),@duty as nvarchar(10)
--拷贝人事系统的离职人员表到临时表#templz
select cast(工号 as int) as 工号,姓名,直间接 into #templz from opendatasource('sqloledb', 'data source=DATABAK ;UID=sa;pwd=).gwidb.dbo.out_TANXUEMEISYSTEMpawf
--拷贝人事系统的在职人员表到临时表#tempzz
select cast(工号 as int) as 工号,姓名,直间接 into #tempzz from opendatasource('sqloledb', 'data source=DATABAK ;UID=sa;pwd=).gwidb.dbo.out_TANXUEMEISYSTEMpawf

declare Cursorpawf cursor
local static for select * from #templz
Open Cursorpawf
while 1=1
begin
fetch Cursorpawf into
@PersonNo
,@Name
,@duty
if @@fetch_status<>0
break
if @PersonNo is not null
begin
---opendatasource('sqloledb', 'data source=SYTELINE ;UID=sa;pwd=SVTEP').SHATDB.dbo.DeptPerson //打开数据表
if exists(select * from syteline.SHATDB.dbo.DeptPerson where PersonNo=@PersonNo)
begin
--存在更新该人员的在职状态
update syteline.SHATDB.dbo.DeptPerson
set Workflag='N'
where PersonNo=@PersonNo
end
else
begin
--不存在不处理
end
end
else
end
close Cursorpawf
deallocate Cursorpawf
--人事在职人员更新处理,(存在更新人员的工号和姓名,不存在新增工号 姓名 在职 直间接)
declare CursorPerf cursor
local static for select cast(工号 as int) as 工号,姓名,直间接 from #tempzz
Open CursorPerf
while 1=1
begin
fetch CursorPerf into
@PersonNo
,@Name
,@duty
if @@fetch_status<>0
break
if @PersonNo is not null
begin
if exists(select * from syteline.SHATDB.dbo.DeptPerson where PersonNo=@PersonNo)
begin
--存在更新该人员的工号和姓名
update syteline.SHATDB.dbo.DeptPerson
set PersonNo=@PersonNo,[Name]=@Name
where PersonNo=@PersonNo
end
else
begin
--不存在新增该人员 工号 姓名 在职状态 和直间接
insert syteline.SHATDB.dbo.DeptPerson(PersonNo,[Name],Workflag,duty)values(@PersonNo,@Name,'Y',@duty)
end
end
else
end
close CursorPerf
deallocate CursorPerf
end
drop table #templz
drop table #tempzz

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值