IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_g_myworkinfo_report]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_g_myworkinfo_report]
GO
 
 
CREATE procedure [dbo].[mps_g_myworkinfo_report](
@cmpid int ,
@useruid int,
@objid bigint  ,
@key nvarchar(50) 
)
as 
begin
set nocount on
declare @i bigint 
set @i = @objid 
if (@i=0) set @i=999999999
select top 10 almmsg_id identid ,almmsg_read msgread,  almmsg_objid objid , almmsg_title objtype , '' objaction, almmsg_date objdate,
almmsg_text objmessage , almmsg_category objctgtype, almmsg_ctgid objid1,almmsg_ctgid2 objid2  ,'' objtitle  ,1 objcount  
from mps_alarm_message  with(nolock) 
where almmsg_cmpid=@cmpid and almmsg_cuid=@useruid  and almmsg_id<@i   and almmsg_type='report' and 
( almmsg_text like '%'+@key+'%' or almmsg_title like '%'+@key+'%' or almmsg_category like '%'+@key+'%' 
or almmsg_objtype like '%'+@key+'%'  )
order by almmsg_read desc , almmsg_date desc , almmsg_id desc 
set nocount off
end