  
  
CREATE procedure [dbo].[p_dailyclose]   
as  
declare @rtn_cnt  int  
        ,@arg_date varchar(10)  
        ,@arg_maxdate varchar(10)  
        ,@arg_todate varchar(10)  
  
    select @arg_todate = convert(char(8), getdate() -1, 112)  
      
    select @arg_maxdate = isnull(max(mg_date), convert(char(8), getdate() -5, 112))  
      from istyle24_wms..tlomg06l with(nolock)  
     where prg_id = 'p_dailystockclose'  
      
    print '@arg_todate : @arg_maxdate'  
    print @arg_todate +'    : ' + @arg_maxdate  
    print ''  
  
    if @arg_todate > convert(varchar(8), convert(datetime,@arg_maxdate, 112) + 1, 112)  
    begin    
  
        set @arg_date = convert(varchar(8), convert(datetime,@arg_maxdate, 112) + 1, 112)   
        print 'loop'  
  
     while @arg_date < @arg_todate  
     begin  
            print @arg_date  
  
            EXEC istyle24_wms..p_dailystockclose_err @arg_date, null, null, @rtn_cnt OUTPUT  
            set @arg_date = convert(varchar(8), convert(datetime,@arg_date, 112) + 1, 112)  
  
        end  
        print 'end'  
    end  
  
    print '  '  
    print '@arg_todate'  
    print @arg_todate  
  
    EXEC istyle24_wms..p_dailystockclose null, null, null, @rtn_cnt OUTPUT  
  
  