IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_new_menu]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_new_menu]
GO
CREATE procedure [dbo].[mps_new_menu] 
@cmpid int ,
@mn_roleid int ,
@menutype varchar(30),
@terminal int as

begin
    set nocount on 
declare @order1 int
--查询出最后一条排序
select top 1 @order1 = mn_order from mps_menu 
where  mn_cmpid=@cmpid and mn_roleid=@mn_roleid order by mn_order desc 
    set @order1 = isnull(@order1 , 0) 
    set @order1 = @order1 +1
    insert into mps_menu(mn_cmpid,mn_order,mn_title,mn_icon,mn_sub,mn_link,mn_roleid,mn_flag,mn_terminal)
    values(@cmpid,@order1,'菜单名称','',0,'',@mn_roleid,@menutype,@terminal)  
    
    --新增记录查询
    select top 1 * from mps_menu 
where mn_cmpid=@cmpid and mn_roleid=@mn_roleid and mn_flag=@menutype and mn_terminal=@terminal order by mn_order desc 
set nocount off
end