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

-- 生成时间:2018-11-23 16:44:50 by ebs-core  
CREATE  procedure mps_prd2_full(
@cmpid int,  
    @prdid bigint, 
    @useruid int,
    @canedit int ) 
as  
begin  
set nocount on 
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
-- 首先取模板  t1  
declare @pcid int 
declare @pctag int
select @pctag=prd_tag,@pcid=prd_pcid from mps_prd2 where prd_id=@prdid 

declare @tmpid int 

declare @ctidf int 
declare @ctid2 int 
declare @flagstr varchar(30) 
set @flagstr='prd' 
if (@canedit=1) set @flagstr='prddetails' 

set @tmpid = 0 
set @ctid2 = @pcid 
select top 1 @tmpid=tmp_id from mps_template where  tmp_cmpid=@cmpid and tmp_type=@flagstr and tmp_objid=@pcid  

while (@tmpid=0 and @ctid2>0) 
begin
set @ctidf = 0 
select @ctidf = pc_father from mps_prdctg where pc_id=@ctid2 
if (@ctidf>0) 
begin
select top 1 @tmpid=tmp_id from mps_template where  tmp_cmpid=@cmpid and tmp_type=@flagstr and tmp_objid=@ctidf 
set @ctid2 = @ctidf 
end else 
begin
set @ctid2 = 0 
end 
end 

select  * from mps_template where  tmp_id=@tmpid 

-- 返回客户定义表t2  
   select * from mps_prdctg where pc_id=@pcid 
   
  
  -- 返回客户的特殊权限  t3 
    select * from mps_prd2_users where prdp_prdid=@prdid and prdp_cuid=@useruid 
    
    --返回业务单数据 t4
    select * from mps_prd2 where prd_id = @prdid 
    -- 获取业务表主根据扩展数据  t5
    select  * from mps_prd2_0 where prd3_prdid = @prdid 
    
    --返回所有附件  t6
    select *, da_categoryid as datagroup from mps_attach where da_cmpid = @cmpid and da_type = 'prd'+convert(varchar(10),@pctag)   and da_objid = @prdid and da_objid2 = 0 order by da_categoryid 
      
     

--明细表数据
 
----以下是数据源 

--- 以下获取用户自定义SQL afterloaded 


--- 以上获取用户自定义SQL afterloaded 
set nocount off
end