IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[userfunc_562_dgj]') AND type = 'P')
DROP PROCEDURE [dbo].[userfunc_562_dgj]
GO
CREATE PROCEDURE userfunc_562_dgj(@cmpid int,   @branchid int,  @userdpid int,  @useruid int,   @userotid int,  @usersecurity int,@ctgid int,@ctgid2 int,@objid bigint)
as
begin



      if(@userotid = 261)
         select top 100 ord_id,ord_khxm,ord_hm,ord_xcgjsj,ord_creator
         from order_239 WITH(NOLOCK)
         where ord_status = '外呼跟进' and ord_whzt='待跟进' and ord_createdpid =  @userdpid
         order by ord_xcgjsj
      else
         select top 100 ord_id,ord_khxm,ord_hm,ord_xcgjsj,ord_creator
         from order_239 WITH(NOLOCK)
         where ord_status = '外呼跟进' and ord_whzt='待跟进' and ord_createcuid = @useruid
         order by ord_xcgjsj


end