首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

简单,存储过程insert重复的时候不执行,该怎么处理

2012-01-18 
简单,存储过程insert重复的时候不执行CREATEprocedureJW_ResCj@cl_Codechar(10),@YE_Yearchar(10),@YE_Num

简单,存储过程insert重复的时候不执行
CREATE   procedure   JW_ResCj
@cl_Code   char(10),
@YE_Year   char(10),
@YE_Num     char(10)
as
declare   @sql   varchar(8000)

insert   into  
jw_res(JW_RESstnum,JW_RESstname,JW_REScj,JW_RESinsname,JW_RESinscode,
JW_RESinsxz,JW_RESstfy,JW_RESstnj,JW_RESstxz,JW_RESinclcode,JW_RESstcolcode,
JW_RESinthcode,JW_RESinyeyear,JW_RESinyenum,JW_RESinclname,JW_RESstcolname)
select    
_st.jw_stnum,_st.jw_stname,0   as   jw_rescj,   _in.jw_insubname,_in.jw_insubcode,
_in.jw_insubxz,_st.jw_stfy,_st.jw_stxn,_st.jw_stxz,_st.jw_stclcode,_st.jw_stcolcode,
_in.jw_inthcode,_in.jw_inyeyear,_in.jw_inyenum,_in.jw_inclname,_st.jw_stcolname
from   jw_st   _st
inner   join   jw_in   _in   on   _in.jw_inclcode=_st.jw_stclcode

where   _in.jw_inclcode=+@cl_Code   and   _in.jw_inyeyear=+@YE_Year   and   _in.jw_inyenum=+@YE_Num
and   _st.jw_stxn=_in.jw_innj
exec(@sql)
GO

这个是存储过程,批量添加,是3个表之间的.
数据量30W左右,每次插入数据300-1000条不等,
如何限制重复添加?

[解决办法]
CREATE procedure JW_ResCj
@cl_Code char(10),
@YE_Year char(10),
@YE_Num char(10)
as
declare @sql varchar(8000)

SELECT @sql= '
insert into
jw_res(JW_RESstnum,JW_RESstname,JW_REScj,JW_RESinsname,JW_RESinscode,
JW_RESinsxz,JW_RESstfy,JW_RESstnj,JW_RESstxz,JW_RESinclcode,JW_RESstcolcode,
JW_RESinthcode,JW_RESinyeyear,JW_RESinyenum,JW_RESinclname,JW_RESstcolname)
select
_st.jw_stnum,_st.jw_stname,0 as jw_rescj, _in.jw_insubname,_in.jw_insubcode,
_in.jw_insubxz,_st.jw_stfy,_st.jw_stxn,_st.jw_stxz,_st.jw_stclcode,_st.jw_stcolcode,
_in.jw_inthcode,_in.jw_inyeyear,_in.jw_inyenum,_in.jw_inclname,_st.jw_stcolname
from jw_st _st
inner join jw_in _in on _in.jw_inclcode=_st.jw_stclcode

where _in.jw_inclcode= '+@cl_Code + ' and _in.jw_inyeyear= '+@YE_Year + ' and _in.jw_inyenum= '+@YE_Num + '
and _st.jw_stxn=_in.jw_innj '
exec(@sql)
GO

热点排行