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

begin
    
      select ord2_creator, count(ord2_creator) as ord2_count
      from order_241 as m inner join order_241_2 as d
      on m.ord_id = d.ord2_ordid 
      where m.ord_status = '已分配' 
      and d.ord2_sfbd = '否'
      and d.ord2_mdbh = (select dp_code from mps_depart where dp_id = @userdpid)
      group by ord2_creator
   
end