IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_save_exportapi]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_save_exportapi]
GO
CREATE procedure [dbo].[mps_save_exportapi] 
@exp_id int,
@exp_cmpid int,
@exp_name varchar(255),
@exp_sql varchar(max),
@exp_language varchar(255),
@exp_result varchar(255),
@exp_allowip varchar(2000),
@exp_allowtime varchar(1000)
as
begin
set nocount on
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
declare @oldname varchar(255) 
select top 1 @oldname=exp_name from mps_exportapi with(nolock) where exp_id=@exp_id 
set @oldname = ISNULL(@oldname,'') 

declare @samenum int

select @samenum = count(*) from  mps_exportapi where exp_name = @exp_name and exp_cmpid=@exp_cmpid  

if @samenum > 0
begin
select 'error' error,'保存失败！有相同的名称: '+@exp_name  as errorinfo
return 
end else
begin
update mps_exportapi set 
exp_name = case when @exp_name='_none_' then exp_name else @exp_name end,
exp_sql = case when @exp_sql='_none_' then exp_sql else @exp_sql end,
exp_language = case when @exp_language='_none_' then exp_language else @exp_language end,
exp_result = case when @exp_result='_none_' then exp_result else @exp_result end,
exp_allowip = case when @exp_allowip='_none_' then exp_allowip else @exp_allowip end,
exp_allowtime = case when @exp_allowtime='_none_' then exp_allowtime else @exp_allowtime end 
where exp_id=@exp_id
end

-- 将SQL写入mps_sql 
select top 1 @exp_sql=exp_sql , @exp_name=exp_name from mps_exportapi with(nolock) where exp_id=@exp_id 

delete mps_sql where sql_cmpid=@exp_cmpid and sql_name=@oldname
insert into mps_sql(sql_cmpid,sql_name,sql_text,sql_type) 
select @exp_cmpid,@exp_name,@exp_sql , 'MSSQL' 
 
set nocount off
end