IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[ord_1_g_1order_top]') AND type = 'P')
DROP PROCEDURE [dbo].[ord_1_g_1order_top]
GO

CREATE procedure [dbo].[ord_1_g_1order_top](
@cmpid int ,
@ordid bigint 
) as
begin
set nocount on
declare @ordfinished int 
declare @bizid int 
select @bizid=ord_bizid ,@ordfinished=ord_finished from ebs20_order.dbo.order_1 where ord_id=@ordid 
-- 返回当前业务定义t1
select a.*,b.* from mps_biztype a,ebs20_order.dbo.order_1 b where ord_id=@ordid and biz_id=@bizid  
-- 返回当前的工作状态   如果工作已做完，是不需要返回的。  t2
if (@ordfinished=1) 
begin
select a.* , b.* from mps_job a ,  mps_flowwork b 
where  jb_cmpid=@cmpid and jb_crmid=@bizid and jb_ordid=@ordid and jb_isauto=1  and jb_back=1  and jb_wsid=0 and jb_wsstatus=''  and wrk_id=jb_wrkid 
end else 
begin
select 0 none where 0=1 
end
set nocount off
end