IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_g_permission]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_g_permission]
GO
CREATE procedure [dbo].[mps_g_permission] 
@cmpid int ,
@mptype varchar(200),
@mpctgid int ,
@mpgroup int 
as
begin
set nocount on
  declare @s varchar(200) 
  declare @s1 varchar(100) 
  declare @i int 
  set @s = @mptype 
  
  while (@s>'') 
  begin
   set @i = charindex(',',@s) 
   if (@i>0) 
   begin
   set @s1 = substring(@s,1,@i-1) 
   set @s = substring(@s,@i+1,len(@s)-@i) 
   end else 
   begin
   set @s1 = @s 
   set @s = '' 
   end 
   select * from mps_permission  
   where mp_cmpid=@cmpid and mp_type=@s1 and mp_ctgid=@mpctgid and mp_group=@mpgroup  
   order by mp_order,mp_caption 
  end 
  set nocount off
end