IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_g_titlesusers]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_g_titlesusers]
GO
CREATE procedure [dbo].[mps_g_titlesusers](
@cmpid int ,
@myotid int ,
@key nvarchar(100) 
)
as
begin
 set nocount on
if (@key='') 
begin
select * from mps_employee  
where cu_cmpid=@cmpid and cu_otid=@myotid and cu_use=0   
order by cu_dpid , cu_name 
end else 
begin
select * from mps_employee  
where cu_cmpid=@cmpid and cu_otid=@myotid and cu_use=0   and 
(cu_fastkey like '%'+@key+'%' or 
 cu_code like '%'+@key+'%' or 
 cu_name like '%'+@key+'%' or 
 cu_mobile like '%'+@key+'%' or 
 cu_contact like '%'+@key+'%' or 
 cu_position like '%'+@key+'%' or 
 cu_identno like '%'+@key+'%' or 
 cu_email like '%'+@key+'%'  
)
order by cu_dpid , cu_name 
end
set nocount off
end