sql下标越界 如何优化?
按月统计 下标越界,如何更改endtime出错,因为有的月份没的31号。如何优化
for i=1 to month(date)
years=year(date)
starttime=years& "- "&i& "-1 "
endtime=years& "- "&i& "-31 "
date_string= " between ' "&starttime& " ' and ' "&endtime& " ' "
set rec=server.CreateObject ( "adodb.recordset ")
sql= "select count(*) as first from ys_first where first_date "
sql=sql&date_string
Rec.Open sql,session( "connection_string "),3,3
first=Rec.Fields( "first ")
Rec.Close
set rec=nothing
total(i,0)=first
next
------解决方案--------------------for i=1 to month(date)
years=year(date)
starttime=years& "- "&i& "-1 "
if i=12 then
endtime=(years+1) & "- "&1& "-1 "
else
endtime=years & "- "&(i+1)& "-1 "
end if
date_string= " first_date> = ' "&starttime& " ' and first_date < ' "&endtime& " ' "
set rec=server.CreateObject ( "adodb.recordset ")
sql= "select count(*) as first from ys_first where "
sql=sql&date_string
Rec.Open sql,session( "connection_string "),3,3
first=Rec.Fields( "first ")
Rec.Close
set rec=nothing
total(i,0)=first
next