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

create procedure [dbo].[mps_g_order_print_item](
@cmpid int,
@bizid int,
@ordid bigint ,
@jbid bigint 
) as
begin
declare @wrkid int 
declare @ic int 
if (@jbid>0) 
begin
select @wrkid = jb_wrkid from mps_job where jb_id=@jbid 
set @wrkid = isnull(@wrkid,0) 
if (@wrkid=0) 
begin
select @wrkid = jb_wrkid from mps_job_history where jb_id=@jbid 
end
select @ic=count(1) from mps_flowwork where wrk_id=@wrkid and wrk_keyparams like '%print%'
end else 
begin
select @ic=count(1) from mps_biztype where biz_id=@bizid and biz_params like '%print%'
end

set @ic = isnull(@ic,0) 
if (@ic=0) 
begin
select 0 none , 1 none1 where 0=1 
return 
end
if (not exists (select 1 from mps_template where tmp_cmpid=@cmpid and tmp_type='bizprint' and tmp_objid=@bizid)) 
begin
select tmp_id , tmp_caption from mps_template where tmp_cmpid=@cmpid and tmp_type='biz' and tmp_objid=@bizid and tmp_caption='缺省模板' 
end else 
begin
select tmp_id , tmp_caption from mps_template where tmp_cmpid=@cmpid and tmp_type='bizprint' and tmp_objid=@bizid 
end
end