IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_newcodemanagementdetails]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_newcodemanagementdetails]
GO
CREATE procedure [dbo].[mps_newcodemanagementdetails]   
@cmpid int ,  
@ctg varchar(20) ,  --大类名
@smallctg nvarchar(50) ,--小类名
@smallctgEn varchar(50) --小类英文
as  
begin  
    set nocount on   
 declare @order1 int  
 --查询出最后一条排序   
 select top 1 @order1 = bm_order from mps_code   
 where  bm_cmpid=@cmpid and bm_category=@ctg and bm_ctgcaption=@smallctg order by bm_order desc   
    set @order1 = isnull(@order1 , 0)   
    set @order1 = @order1 +1  
    insert into mps_code(bm_cmpid,bm_category,bm_ctg,bm_ctgcaption,bm_text,bm_order)  
    values(@cmpid,@ctg ,@smallctgEn,@smallctg,'',@order1)    
      
      
      
    --新增记录查询  
    select top 1 * from mps_code   
  where bm_cmpid=@cmpid and bm_category=@ctg and bm_ctgcaption=@smallctg order by bm_order   desc   
 set nocount off  
end