sql 2000SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO
ALTER  function slot (@intime datetime ,@outtime datetime,@slot char(100),@maxslot varchar(100))
returns decimal(16,1)
as
begin
declare @nday int,@nhour int ,@nmin int ,@alltime int,@din int,@dout int ,@time int
declare @allmoney money,@allmoneyA money,@allmoneyB money,@allmoneyC money,@allmoneyD money,@allmoneyE money --五个时间段的费用
declare @a int,@b int ,@c int,@d int,@e int,@f int --六个时间点的划分
declare @dintime int ,@douttime int
select @alltime = datediff(minute,@intime,@outtime)select @maxslot=isnull(@maxslot,'000000')
select @allmoney = 0
select @dintime=(select datepart (hour,@intime))*60+(select datepart (minute,@intime))+((select datepart(day,@intime))*60*24) --进入时间分钟数
select @douttime=(select datepart (hour,@outtime))*60+(select datepart (minute,@outtime))+((select datepart(day,@outtime))*60*24) --出去时间分钟数
select @nday = (@douttime-@dintime)/60/24  --天数
select @nhour = (@alltime-@nday*24*60)/24 --小时
select @nmin = @alltime-@nday*24*60-@nhour*60+1 --分钟select  @a = 0 ,
@b =(convert(int,substring(@slot,3,2))*60)+((select datepart(day,@intime))*60*24),
@c =(convert(int,substring(@slot,5,2))*60)+((select datepart(day,@intime))*60*24),
@d =((convert(int,substring(@slot,3,2))+24)*60)+((select datepart(day,@intime))*60*24),
@e =((convert(int,substring(@slot,5,2))+24)*60)+((select datepart(day,@intime))*60*24),
@f =((24+24)*60)+((select datepart(day,@intime))*60*24)
--@a 0点  @b 10点 @c  20点  @d  是第二天10点  @e  第二天20点  @f  第二天结束  0点即48小时begin
if @alltime<=convert(int,substring(@slot,1,2))
return @allmoney
elsebegin if @dintime>=@a
set @din=@dintime
else
set @din=0
if @douttime<@b
set @dout=@douttime
else
set @dout=@b
end
begin
if @dout-@din<=0
set @allmoneyA=0
else
if (@dout-@din)<convert(int,substring(@slot,14,1))
set @allmoneyA=convert(int,substring(@slot,15,2))
else
if @allmoneyA>=convert(int,substring(@maxslot,4,3))
set @allmoneyA=convert(int,substring(@maxslot,4,3))
else
if (@dout-@din)%60<>0
set @allmoneyA=((@dout-@din)/60)*convert(int,substring(@slot,12,2))+convert(int,substring(@slot,12,2))
else
set @allmoneyA=((@dout-@din)/60)*convert(int,substring(@slot,12,2))
end
--在第一天内0点至特殊收费段前的时间段的收费
begin
if @dintime>=@b
set @din=@dintime
else
set @din=@b
if @douttime<@c
set @dout=@douttime
else
set @dout=@c
end
begin
if @dout-@din<=0
set @allmoneyB=0
else
if (@dout-@din)<convert(int,substring(@slot,9,1))
set @allmoneyB=convert(int,substring(@slot,10,2))
else
if @allmoneyB>=convert(int,substring(@maxslot,1,3))
set @allmoneyB=convert(int,substring(@maxslot,1,3))
else
if (@dout-@din)%60<>0
set @allmoneyB=((@dout-@din)/60)*convert(int,substring(@slot,7,2))+convert(int,substring(@slot,7,2))
else
set @allmoneyB=((@dout-@din)/60)*convert(int,substring(@slot,7,2))
end
--在第一天之内特殊收费段的时间段的收费
begin
if @dintime>=@c
set @din=@dintime
else
set @din=@c
if @douttime<@d 
set @dout=@douttime
else
set @dout=@d
endbegin
if @dout-@din<=0
set @allmoneyC=0
else
if (@dout-@din)<convert(int,substring(@slot,14,1))
set @allmoneyC=convert(int,substring(@slot,15,2))
else
if @allmoneyC>=convert(int,substring(@maxslot,4,3))
set @allmoneyC=convert(int,substring(@maxslot,4,3))
else
if (@dout-@din)%60<>0
set @allmoneyC=((@dout-@din)/60)*convert(int,substring(@slot,12,2))+convert(int,substring(@slot,12,2))
else
set @allmoneyC=((@dout-@din)/60)*convert(int,substring(@slot,12,2))
end
--在第一天特殊收费的后时间点到第二天特殊收费的前时间点
begin
if @dintime>=@d
set @din=@dintime
else
set @din=@d
if @douttime<@e
set @dout=@douttime
else
set @dout=@e
end
begin
if @dout-@din<=0
set @allmoneyD=0
else
if @dout-@din<convert(int,substring(@slot,9,1))
set @allmoneyD=convert(int,substring(@slot,10,2))
else
if @allmoneyD>=convert(int,substring(@maxslot,1,3))
set @allmoneyD=convert(int,substring(@maxslot,1,3))
else
if (@dout-@din)<>0
set @allmoneyD=((@dout-@din)/60)*convert(int,substring(@slot,7,2))+convert(int,substring(@slot,7,2))
else
set @allmoneyD=((@dout-@din)/60)*convert(int,substring(@slot,7,2))
end
--在第二天之内特殊收费段的时间段的收费
begin
if @dintime>=@e
set @din=@dintime
else
set @din=@e
if @douttime<@f
set @dout=@douttime
else
set @dout=@f
end
begin
if @dout-@din<=0
set @allmoneyE=0
else
if (@dout-@din)<convert(int,substring(@slot,14,1))
set @allmoneyE=convert(int,substring(@slot,15,2))
else
if @allmoneyE>=convert(int,substring(@maxslot,4,3))
set @allmoneyE=convert(int,substring(@maxslot,4,3))
else
if (@dout-@din)%60<>0
set @allmoneyE=((@dout-@din)/60)*convert(int,substring(@slot,12,2))+convert(int,substring(@slot,12,2))
else
set @allmoneyE=((@dout-@din)/60)*convert(int,substring(@slot,12,2))
end
--在第二天的特殊时间后时间点到第二天的0点即24小时一用48小时
set @allmoney=@allmoneyA+@allmoneyB+@allmoneyC+@allmoneyD+@allmoneyE
begin
if @nday>=1
set @allmoney=(convert(int,substring(@maxslot,7,3))*@nday)+@allmoney
else
if @allmoney>=convert(int,substring(@maxslot,7,3))   
set @allmoney=convert(int,substring(@maxslot,7,3))
else
set @allmoney=@allmoneyA+@allmoneyB+@allmoneyC
end
end
return @allmoney
end
GO
select dbo.slot('2012-8-8 3:10','2012-8-12 3:10',
'1010201523010220','200100300')后面连个字段分别是 两个时间点加上
A:免收_10分钟,_10点~_20点每小时收费_15元,期间小于2_小时收费_30元,每日限额_200元,其他时段每小时收费_10元,期间小于_2小时收费20_元最高100元。每天最高300元
这就是条件
要得到的结果就是 对收费的多少  
我的程序已经调通了  就是在细节上还不符合要求
求大神帮忙简单修改

解决方案 »

  1.   

    建议标注出具体错误所在代码段
      

  2.   

    你的条件还有叙述不清的地方
    1、每日是按自然日,还是停车开始后的每24小时为一日
    2、特殊时段每小时15,最低30,普通时段每小时10,最低20,你没有叙述两者交叉的情况,例如停车3小时,特殊普通各占1.5小时,如何收费
    3、每天特殊时段只有10小时,每小时15,何来每日最高200,每日停满也只有150
      

  3.   

    貌似没有什么错误啊,我编译通过了,你给出具体错误的代码行看看