[求助]求助:存储过程写法
<P ><FONT face="Times New Roman">1. </FONT>假设有以下的两个表:<o:p></o:p></P><P >Cus_A<o:p></o:p></P>
<TABLE cellSpacing=0 cellPadding=0 width=576 border=1>
<TR >
<TD vAlign=top width=157>
<P >ID*<o:p></o:p></P></TD>
<TD vAlign=top width=216>
<P >Name<o:p></o:p></P></TD>
<TD vAlign=top width=203>
<P >Address<o:p></o:p></P></TD></TR>
<TR >
<TD vAlign=top width=157>
<P >…<o:p></o:p></P></TD>
<TD vAlign=top width=216>
<P >…<o:p></o:p></P></TD>
<TD vAlign=top width=203>
<P >…<o:p></o:p></P></TD></TR></TABLE>
<P >Cus_B<o:p></o:p></P>
<TABLE cellSpacing=0 cellPadding=0 width=576 border=1>
<TR >
<TD vAlign=top width=157>
<P >ID*<o:p></o:p></P></TD>
<TD vAlign=top width=216>
<P >Name<o:p></o:p></P></TD>
<TD vAlign=top width=203>
<P >Address<o:p></o:p></P></TD></TR>
<TR >
<TD vAlign=top width=157>
<P >…<o:p></o:p></P></TD>
<TD vAlign=top width=216>
<P >…<o:p></o:p></P></TD>
<TD vAlign=top width=203>
<P >…<o:p></o:p></P></TD></TR></TABLE>
<P >*主键<o:p></o:p></P>
<P >表Cus_A和表Cus_B的结构完全相同,表Cus_A和表Cus_B中既存在ID相同的记录,也存在ID不同的记录。现要求将ID只存在于表Cus_A中而不存在于表Cus_B中的记录全部插入到Cus_B表中,并用表Cus_A中的记录更新表Cus_B中相同的ID的记录,请写出完成这一功能的存储过程。<o:p></o:p></P> <P>create procedure dd<BR>as<BR>begin</P>
<P>select * into #temp from b where 1<>1</P>
<P>insert into #temp<BR>select * from b<BR>union all<BR>select * from a<BR>where a.id not in <BR>(select id from b )<BR>update #temp<BR>set #temp.name=a.name<BR>#temp.address=a.address<BR>where #temp.id=a.id<BR>select * from #temp<BR>end</P>
页:
[1]
