+ -
当前位置:首页 → 问答吧 → 求 修改一个存储过程...

求 修改一个存储过程...

时间:2011-11-29

来源:互联网

SQL code
tb_pr:
   col1           TimeIn            
   A001        2011-01-21 07:48:03 
   A002        2011-01-21 07:48:33
   A003        2011-01-21 07:49:23
   A004        2011-01-21 08:20:30
   A005        2011-01-21 08:21:00
   A006        2011-01-21 08:22:36
   A007        2011-01-21 08:23:22
   A008        2011-01-21 08:24:03   


//该存储过程的作用是统计 tb_pr中 两个 TimeIn之间的时间差
 把所有的时间差再统计(两者之间的标准时间差为 30,如果大于30 
                        如:35 那么统计时间时 就计 5)
   
CREATE PROCEDURE [dbo].[sp_leadTime]
@startTime    datetime,
@endTime    datetime
AS
declare        @standardProcessingTime        datetime
declare        @totalLeadTime            datetime
declare        @cur_TimeIn1            datetime
declare        @cur_TimeIn2            datetime

set @standardProcessingTime = '00:00:30'
set @totalLeadTime = '00:00:00'

set rowcount 1
    select @cur_TimeIn1 = TimeIn 
      FROM tb_pr
        where TimeIn > @startTime and TimeIn < @endTime
        and Line_ID = 'C' order by TimeIn desc 
set rowcount 0

    declare windingCursor CURSOR for 
        select TimeIn       FROM tb_pr
            where TimeIn > @startTime and TimeIn < @endTime
            and Line_ID = 'C' order by TimeIn desc 

    Open windingCursor
        Fetch next from windingCursor into @cur_TimeIn2
        
    While @@FETCH_STATUS = 0
        begin
            if @cur_TimeIn1 <> @cur_TimeIn2 
                begin
                    set @totalLeadTime = @totalLeadTime + (@cur_TimeIn1 - @cur_TimeIn2 - @standardProcessingTime)
                end
            set @cur_TimeIn1 = @cur_TimeIn2
            Fetch next from windingCursor into @cur_TimeIn2        
        end    
    
    close windingCursor
    deallocate windingCursor

select convert(varchar(8), @totalLeadTime, 108)


SQL code
//现在添加 一个新的表,当在上面存储过程中传入的时间为 这表中时间段时,该时间就不用统计 
 如上面存储过程传入的时间为 2011-01-21 07:48:03  ,2011-01-21 10:48:03 
 则统计出来的时间要减去  30分钟(07:50 - 08:20)    
tb_sys:
  StopName    StartTime       EndTime
     早        07:50           08:2011:30           12:2017:50           18:3012:30           01:30 



请问在上面的存储过程中怎么实现??

作者: yikeda   发布时间: 2011-11-29

要是交叉怎么办?

作者: xuam   发布时间: 2011-11-29

vfp9.0
copy tb_pr to tb_prback
alter table tb_prback add column cha n(10)
use tb_prback
go 1
startTimeIn=TimeIn  
scan
m.TimeIn=TimeIn  
ncha=m.TimeIn-startTimeIn  
if ncha<=30
  repl cha with ncha
  else 
  repl cha with mod(ncha/30)
endif
endscan

 

作者: jxjdzwang5555   发布时间: 2011-11-29

就是去掉交叉 的时间差哦...

作者: yikeda   发布时间: 2011-11-29

引用 2 楼 jxjdzwang5555 的回复:
vfp9.0
copy tb_pr to tb_prback
alter table tb_prback add column cha n(10)
use tb_prback
go 1
startTimeIn=TimeIn
scan
m.TimeIn=TimeIn
ncha=m.TimeIn-startTimeIn
if ncha<=30
repl cha wi……



能不能再 写详细点。。。。。。。

谢谢?

作者: yinliaobao   发布时间: 2011-11-29

热门下载

更多