Create PROCEDURE GetShenHeSL
  @CurUser Varchar(50),
  @JGPathKeyListStr Varchar(1000),
  @Dsh int output,
  @wcl int output,
  @csl int output
As
Begin
  Declare @Sql Varchar(1000)
  Declare @SqlBase Varchar(1000)
  Declare @Sql2 Varchar(1000)
  Declare @Sql3 Varchar(1000)
  Declare @Sql4 Varchar(1000)
  
  Declare @Djlx Varchar(100)
  Declare @tmpSL int
  Declare @TableName Varchar(100)
  Set @Dsh=0 
  Set @wcl=0
  Set @csl=0
  Set @tmpSL=0
  Set @Sql='Declare cur1 Cursor For select 单据名称,表名 from 单据表 where 启用多级审核=1'
  Exec(@Sql)
  Open cur1 --这个是启动多级审核的单据
  Fetch Next From cur1 into @Djlx,@TableName 
  While (@@Fetch_Status=0)
  Begin 
    IF (@TableName='材料总账表') Begin Set @SqlBase='Declare cur2 Cursor Global For select count(*) from 材料总账表 As DJB where 冲销=0  And 单据类型='''+@djlx+''' ' End
    IF (@TableName<>'材料总账表') Begin Set @SqlBase='Declare cur2 Cursor Global For select count(*) from (select '''+@djlx+''' As 单据类型,* from '+@TableName+') As DJB where 冲销=0 ' End 
    Set @Sql2=@SqlBase+' And CharIndex('''+@CurUser +''',待审人)>0 '    
    Exec(@Sql2)
    Open cur2  
    Fetch Next From cur2 into @tmpSL
    Set @Dsh=@Dsh+@tmpSL
    Close cur2
    deallocate cur2
    
    Set @Sql3=@SqlBase+'And 待抄送人处理=1 And  CharIndex('';'+@CurUser +';'','';''+抄送人)>0 And CharIndex('';'+@CurUser +';'','';''+已处理抄送人)<1'
    Exec(@Sql3)
    Open cur2 
    Fetch Next From cur2 into @tmpSL
    Set @wcl=@wcl+@tmpSL
    Close cur2
    deallocate cur2
 
    Set @Sql4=@SqlBase+'And (审核否=1 or 抄送类别=''审核前抄送'')  And  (CharIndex('';'+@CurUser +';'','';''+抄送人)>0 or '+@JGPathKeyListStr+')'
    Exec(@Sql4)
    Open cur2 
    Fetch Next From cur2 into @tmpSL
    Set @csl=@csl+@tmpSL
    Close cur2
    deallocate cur2



    Fetch Next From cur1 into @Djlx,@TableName   
  End
  Close cur1
  deallocate cur1 


End

