IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_save_permission_sql]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_save_permission_sql]
GO
CREATE procedure [dbo].[mps_save_permission_sql](
@mpid int,
@mpsql nvarchar(2000) 
)
as
begin
declare @cap nvarchar(200) 
select @cap=mp_caption from mps_permission where mp_id=@mpid 
set @cap = isnull(@cap ,'') 
-- <span class='glyphicon glyphicon-filter f12 fontalternate'></span>
declare @i int 
set @i = charindex('></span>',@cap) 
if (@i>0) 
begin
set @cap = substring(@cap,@i + 8,LEN(@cap)-@i -8) 
end
if (@mpsql>'') 
begin
set @cap = '<span name=filter class=''glyphicon glyphicon-filter f12 fontalternate''></span>'+@cap 
end else 
begin
set @cap = '<span name=filter class=''glyphicon glyphicon-filter f12 fontalternate hidden''></span>'+@cap 
end

update mps_permission set mp_sql=@mpsql , mp_caption=@cap where mp_id=@mpid 
end