IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_g_1branch_title]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_g_1branch_title]
GO
CREATE procedure [dbo].[mps_g_1branch_title](
@cmpid int,
@mybcid int,
@key nvarchar(255)
)
as 
begin
-- 返回岗位
set nocount on
if(@key = '_none_' or @key = '') set @key = ''
else set @key = '%'+@key+'%'

declare @tt table(otid int) 
insert into @tt(otid) 
select distinct dt_otid 
from mps_depart_title , mps_depart 
where dp_cmpid=@cmpid and dp_bcid=@mybcid and dt_dpid=dp_id 

select top 500 ot_id , ot_title,ot_display 
from mps_title , @tt 
where ot_id=otid and ot_title>'' and ot_display>'' 
  and  (@key = '' or ot_title like @key)
order by ot_order 
set nocount off
end