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

select top 50 jb_id identid ,1 msgread, jb_id objid , jb_ordtype objtype , 1 objcount, 'biz' objctgtype,jb_crmid objid1,jb_ordid objid2 , 
CONVERT(varchar(10),jb_date,120)+' / '+jb_ordcreator++' / '+jb_ordno+case when jb_ordtitle='' then '' else ' / '+jb_ordtitle end +' / '+jb_title objtitle   ,
'<a>'+CONVERT(varchar(5),jb_date,10)+' '+CONVERT(varchar(5),jb_date,8)+'/'+jb_ordcreator+'/'+jb_title+'</a>' objtitlemobile   ,
'' objtitle1 , '' objtitle2 , 1 objcount 
from mps_job  with(nolock) 
where jb_cmpid=@cmpid and jb_cuid=@useruid and jb_wsid=0 and jb_isauto=1 and jb_enabled=0 and jb_back=1 and jb_id<@minjbid  and jb_showinundo=0 and 
jb_crmid=@objid and 
(jb_ordtype like '%'+@key+'%' or jb_ordno like '%'+@key+'%' or  jb_ordtitle like '%'+@key+'%'
or  jb_ordcreator like '%'+@key+'%' or  jb_backinfo  like '%'+@key+'%' 
or  jb_ordstatus  like '%'+@key+'%' or   jb_title   like '%'+@key+'%')  and jb_ordno not like '%临%'
order by jb_id desc 

set nocount off
end