就是现在我要写一个存储过程,但是我不知道该怎么写,所以就麻烦各位兄弟帮我写下
具体需求:数据库a,数据库b。现在我需要更新数据库a里面的atable表,而atable表的数据是从b数据库的btable表里面拿出来的。
atable表里面有(ID,SCODE,SNAME,BCODE,BNAME,BORDERID)列;
btable表里面有(ID,MNAME,BNAME,STATUS,BOXTOSSU)列;
现在我需要将btable表里面的MNAME,BNAME列的数据分别更新到atable表里面的SNAME,BNAME列里面,atable的ID是自动增长,别的列的数据是输入的这不用管了。
现在只有拿这个数据该怎么写?麻烦各位兄弟帮帮我,存储过程不怎么会..谢谢了。
具体需求:数据库a,数据库b。现在我需要更新数据库a里面的atable表,而atable表的数据是从b数据库的btable表里面拿出来的。
atable表里面有(ID,SCODE,SNAME,BCODE,BNAME,BORDERID)列;
btable表里面有(ID,MNAME,BNAME,STATUS,BOXTOSSU)列;
现在我需要将btable表里面的MNAME,BNAME列的数据分别更新到atable表里面的SNAME,BNAME列里面,atable的ID是自动增长,别的列的数据是输入的这不用管了。
现在只有拿这个数据该怎么写?麻烦各位兄弟帮帮我,存储过程不怎么会..谢谢了。
这个?
insert 数据库a.dbo.atable (sname,bname)
select name,bname from 数据库b.dbo.btable
你的数据对应只有2个Name,其他的栏位用什么更新啊?
select * from OPENROWSET('MSDASQL', 'DRIVER={SQL Server};SERVER=aaa;UID=sa;PWD=', 数据库b.dbo.btable )
@name varchar(10) = null
as
begin
if @id is null
insert dbo.atable (sname,bname)
select b.sname,b.bname from dbo.atable a left join dbo.btable b
on a.sname= b.sname and a.bname= b.bname
where b.bname is not null and b.sname is not nullelse
insert dbo.atable (sname,bname)
select b.sname,b.bname from dbo.atable a left join dbo.btable b
on a.sname= b.sname and a.bname= b.bname
where b.bname is not null and b.sname is not null and b.bname = @name
end