IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_g_myworkinfo_task_details]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_g_myworkinfo_task_details]
GO
CREATE procedure [dbo].[mps_g_myworkinfo_task_details](
@cmpid int ,
@useruid int,
@objid bigint  ,
@type nvarchar(50),
@key nvarchar(50)  ,
@minjbid bigint 
)
as 
begin
set nocount on
if (@minjbid is null or @minjbid=-999999999) set @minjbid= 999999999

 
select top 50 tsk_id identid , 1 msgread, tsk_id objid , tsk_type objtype ,  '' objaction, tsk_date objdate,
convert(varchar(16),tsk_date,120)+' / '+tsk_message objtitle , 
convert(varchar(16),tsk_date,120)+'<br><a>'+tsk_message+'</a>' objtitlemobile , 
tsk_objtype objctgtype, tsk_ctgid objid1,tsk_objid objid2 ,
'' objtitle1 , '' objtitle2 , 1 objcount 
from mps_task  with(nolock) 
where tsk_cmpid=@cmpid and tsk_cuid=@useruid  and tsk_id<@minjbid   and 
tsk_type = case when @type='' then tsk_type else @type end and 
( tsk_depart like '%'+@key+'%' or tsk_cuname like '%'+@key+'%' or tsk_objtype like '%'+@key+'%' 
or tsk_message like '%'+@key+'%' or tsk_type like '%'+@key+'%' or tsk_branch like '%'+@key+'%')
order by tsk_id desc 
set nocount off
end