日期:2014-05-17  浏览次数:20928 次

如何读取特定日期的记录?
例如我表里有   abc   字段和   时间类的   adcdate   格式是   2007-6-9

如何按年月统计   abc   ????   就如我想统计   2007年6月的   abc总额

谢谢!

------解决方案--------------------
fromyear=clng(request( "fromyear "))
'搜索起始时间年份
frommonth=clng(request( "frommonth "))
'搜索起始时间月份
fromday=clng(request( "fromday "))
'搜索起始时间具体日期
endyear=clng(request( "endyear "))
'搜索终止时间年份
endmonth=clng(request( "endmonth "))
'搜索终止时间月份
endday=clng(request( "endday "))
'搜索终止时间具体日期
if fromyear <> 0 then
'当起始时间年份不等于O的情况下
fromdate=cstr(fromyear)& "- "&cstr(frommonth)& "- "&cstr(fromday)
'连接字符串
end if
if endyear <> 0 then
'当终止时间年份不等于O的情况下
enddate=cstr(endyear)& "- "&cstr(endmonth)& "- "&cstr(endday)
'连接字符串
end if
if fastbl <> 0 then
'判断搜索时间范围是否为0
select case fastbl
case 1
'搜索今天符合条件的数据
fromdate=date()
enddate=dateadd( "s ",-1,(dateadd( "d ",1,fromdate)))
case 2
'搜索昨天符合条件的数据
fromdate=dateadd( "d ",-1,date())
enddate=dateadd( "s ",-1,(dateadd( "d ",1,fromdate)))
case 3
'搜索前天符合条件的数据
fromdate=dateadd( "d ",-2,date())
enddate=dateadd( "s ",-1,(dateadd( "d ",1,fromdate)))
case 4
'搜索本星期符合条件的数据
fromdate=dateadd( "d ",2-weekday(date()),date())
enddate=dateadd( "d ",7,fromdate)
case 5
'搜索上星期符合条件的数据
fromdate=dateadd( "d ",1-weekday(date())-7,date())
enddate=dateadd( "d ",7,fromdate)
case 6
'搜索本月符合条件的数据
fromdate=cstr(year(date()))& "- "&cstr(month(date()))& "-1 "
enddate=dateadd( "s ",-1,(dateadd( "m ",1,fromdate)))
end select
end if
sql= "select sum(abc) as expr1 from tablename where 1=1 "
if fromdate <> " " then
if enddate <> " " then
sql=sql& " and (abcdate between ' "&fromdate& " ' and ' "&enddate& " ') "
else
sql=sql& " and (abcdate between ' "&fromdate& " ' and getdate()) "
end if
end if