IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_new_weixin_subgroup]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_new_weixin_subgroup]
GO

-- =============================================
-- Author:<Author,,Name>
-- Create date: <Create Date,,>
-- Description:<Description,,>
-- =============================================
CREATE procedure [dbo].[mps_new_weixin_subgroup]
@cmpid int,
@roleid int,
@headerid int
AS
BEGIN
declare @groupid int
declare @order int
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
--获取分组
select @groupid=max(mn_group) from mps_menu where mn_cmpid=@cmpid and mn_roleid=@roleid and mn_flag like '%_sub'+CONVERT(varchar,@headerid);
set @groupid=ISNULL(@groupid,0)
--获取序号
--select @order=max(mn_order) from mps_menu where mn_cmpid=@cmpid and mn_roleid=@roleid and mn_group=@groupid
insert into mps_menu(mn_cmpid,mn_terminal,mn_roleid,mn_flag,mn_title,mn_group,mn_order,mn_sub) values(@cmpid,1,@roleid,'title_s_sub'+convert(varchar,@headerid),'分组标题',@groupid+1,0,@headerid);
END