IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_customer_full]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_customer_full]
GO
create  procedure [dbo].[mps_customer_full](
@cmpid int,  
    @ccid bigint, 
    @useruid int,
    @canedit int ) 
as  
begin  
set nocount on 
-- 首先取模板  t1  
declare @ctid int 
declare @cctag int
select @cctag=cc_tag,@ctid=cc_ctid from mps_customer where cc_id=@ccid 
declare @tmpid int 
declare @ctidf int 
declare @flagstr varchar(30) 
set @flagstr='cst' 
if (@canedit=1) set @flagstr='cstdisp' 
set @tmpid = 0 
set @ctidf = @ctid 
select top 1 @tmpid=tmp_id from mps_template where  tmp_cmpid=@cmpid and tmp_type=@flagstr and tmp_objid=@ctid  
select  * from mps_template where  tmp_id=@tmpid 



-- 返回客户定义表t2  
   select * from mps_csttype where ct_id=@ctid 
   
  
  -- 返回客户的特殊权限  t3 
    select * from mps_customer_users where ccp_ccid=@ccid and ccp_cuid=@useruid 
    
    --返回业务单数据 t4
    select * from mps_customer where cc_id = @ccid 
    -- 获取业务表主根据扩展数据  t5
    select  * from mps_customer_0 where cc3_ccid = @ccid 
    
    --返回所有附件  t6
    declare @type1 varchar(50)
    if @cctag = 0 set @type1 = 'cst'
    else set @type1 = 'cst'+convert(varchar(10),@cctag)
    select *, da_categoryid as datagroup from mps_attach where da_cmpid = @cmpid 
    and da_type =  @type1  and da_objid = @ccid and da_objid2 = 0 order by da_categoryid 
      
     

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

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


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