准备在ACCESS里建一个时间段的费率表
根据得到的进入时间和离开的时间,判断在哪个时间段内,然后根据表内的不同费率,计算所需支付的费用(跨不同时间段的,分别计算在各段时间内的费用)时间段:              费率
7:00--15:00            80%
15:00--22:00           100%
22:00--7:00            50%最终结果记录在已有的一张表的一个字段急着用,请大家帮帮忙,谢谢
贡献现在所有积分

解决方案 »

  1.   

    没有难度,就是麻烦。假定时间段不超过 24 小时,也不跨越 7:00,并假定你的时间单位是分钟 :Dim curFee As Currency, datDuration As Date
    Dim datStart As Date, datEnd As DatedatDuration = dataEnd - datdataStart
    dataStart = Int(dataStart)
    dataEnd = dataStart + datDurationIf datStart < "15:00" Then
        If dataEnd < "15:00" Then
            curFee = DateDiff("n", datStart, datEnd) * 单价 * 80%
        Else
            curFee = DateDiff("n", datStart, "15:00") * 单价 * 80%
            If dataEnd < "22:00" Then
                curFee = curFee + DateDiff("n", "15:00", datEnd) * 单价
            Else
                curFee = curFee + DateDiff("n", "15:00", "22:00") * 单价
                  curFee = curFee + DateDiff("n", "22:00", datEnd) * 单价 * 50%
            End If
        End If
    Else
        If datStart < "22:00" Then
            If datEnd < "22:00" Then
                curFee = DateDiff("n", datStart, datEnd) * 单价
            Else
                curFee = DateDiff("n", datStart, "22:00") * 单价
                  curFee = curFee + DateDiff("n", "22:00", datEnd) * 单价 * 50%
            End If
        Else
            curFee = DateDiff("n", datStart, datEnd) * 单价 * 50%
        End If
    End If
      

  2.   


    直接用SWITCH更改UPDATE tb 
    SET f_value = switch(cdate(f_date)<cdate("6:59"),f_value*50/100,
                         cdate(f_date)<cdate("14:59"),f_value*80/100,
                         cdate(f_date)<cdate("21:59"),f_value,
                         cdate(f_date)<cdate("23:59"),f_value*50/100);
      

  3.   

    "没有难度,就是麻烦。假定时间段不超过   24   小时,也不跨越   7:00,并假定你的时间单位是分钟   : Dim   curFee   As   Currency,   datDuration   As   Date 
    Dim   datStart   As   Date,   datEnd   As   Date datDuration   =   dataEnd   -   datdataStart 
    dataStart   =   Int(dataStart) 
    dataEnd   =   dataStart   +   datDuration If   datStart   <   "15:00 "   Then 
            If   dataEnd   <   "15:00 "   Then 
                    curFee   =   DateDiff( "n ",   datStart,   datEnd)   *   单价   *   80% 
            Else 
                    curFee   =   DateDiff( "n ",   datStart,   "15:00 ")   *   单价   *   80% 
                    If   dataEnd   <   "22:00 "   Then 
                            curFee   =   curFee   +   DateDiff( "n ",   "15:00 ",   datEnd)   *   单价 
                    Else 
                            curFee   =   curFee   +   DateDiff( "n ",   "15:00 ",   "22:00 ")   *   单价 
                                curFee   =   curFee   +   DateDiff( "n ",   "22:00 ",   datEnd)   *   单价   *   50% 
                    End   If 
            End   If 
    Else 
            If   datStart   <   "22:00 "   Then 
                    If   datEnd   <   "22:00 "   Then 
                            curFee   =   DateDiff( "n ",   datStart,   datEnd)   *   单价 
                    Else 
                            curFee   =   DateDiff( "n ",   datStart,   "22:00 ")   *   单价 
                                curFee   =   curFee   +   DateDiff( "n ",   "22:00 ",   datEnd)   *   单价   *   50% 
                    End   If 
            Else 
                    curFee   =   DateDiff( "n ",   datStart,   datEnd)   *   单价   *   50% 
            End   If 
    End   If 以上是2楼的回答,但是1)定义有问题,一会是datStart,一会儿是dataStart,不统一。即使统一改过来,还是提示:实时错误5,无效的过程调用或参数   curFee   =   DateDiff( "n ",   datStart,   datEnd)   *   单价   *   80%能帮忙看看吗?