IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_new_report]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_new_report]
GO
create procedure [dbo].[mps_new_report]   
@cmpid int,
@rpt_title nvarchar(100),    
@rpt_category nvarchar(100),    
@rpt_categorysub nvarchar(100)    
as    
begin    
 set nocount on    
 --set @rpt_title = case when @rpt_title='_none_' then '' else @rpt_title end     
 set @rpt_category =  case when @rpt_category='_none_' or @rpt_category='' then @rpt_title else @rpt_category end     
 set @rpt_categorysub = case when @rpt_categorysub='_none_' then '' else @rpt_categorysub end     
     
 insert into mps_report(rpt_cmpid,rpt_title,rpt_category,rpt_categorysub)    
 values(@cmpid,@rpt_title,@rpt_category,@rpt_categorysub)    
    
 select top 1 rpt_id,rpt_title from mps_report 
 where rpt_cmpid = @cmpid and rpt_title = @rpt_title and rpt_category = @rpt_category
 and rpt_categorysub = @rpt_categorysub
 order by rpt_id desc
end