ASP中SQL问题?

ahsteven 2007-09-05 09:07:07
各位高手,我想求2007-5-1到2007-9-1之间的总数,为何总是出错?

错误类型:
Microsoft JET Database Engine (0x80040E21)
试图执行的查询中不包含作为合计函数一部分的特定表达式 'S_date' 。

SQL语句如下:
sql="Select sum(Total) as abcd from TTR_Stock where S_date>=#2007-5-1# and S_date<=#2007-9-1# order by S_date Desc"
...全文
207 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
meng123668185 2007-09-06
  • 打赏
  • 举报
回复
试下:
sql="Select sum(Total) as abcd from TTR_Stock where S_date>='"2007-5-1"' and S_date<='"2007-9-1"' order by S_date Desc"
yelinn 2007-09-06
  • 打赏
  • 举报
回复
用datediff 44
generalmax 2007-09-06
  • 打赏
  • 举报
回复
sql="select * from TTR_Stock where S_date>=#"&start1&"# and S_date<=#"&end1&"# and Consignor='"&Cus&"'order by S_date Desc"
rc.open sql,conn,1,1

Dim pagenum
rs.pagesize = 5 '每页显示记录的条数
pagecount1 = rs.pagecount '总共显示的页数
'获取当前的页码数,放到变量pagenum中
If request.querystring("pagenum") = 0 Or request.querystring("pagenum") = "" Then
pagenum = 1
Else
pagenum = request.querystring("pagenum")
rs.absolutepage = Trim(request.querystring("pagenum")) '记录集的absolutepage属性表示当前显示的第几页
End If

<%if not rs.eof then
mn1=0:mn2=0:mn=0
p=0:do while not rs.eof and p<rs.pagesize
%>

<%mn=cint(rs("money"))+mn %>
<%p=p+1:rs.movenext:loop%>
<%else%>
暂时没有信息!
<%end if%>
<td><% ipzh="http://"&Request.ServerVariables("server_name")&Request.ServerVariables("script_name")& "?" & Request.queryString
if right(ipzh,1)="?" then ipzh=ipzh&"st=0"
ipzh=replace(ipzh,"pagenum","zhh")%>
<%if rs.recordcount>rs.pagesize then%>
[<a href=<%=ipzh%>&pagenum=1 class="main">首页</a>
<%If pagenum > 1 Then%>
<a href=<%=ipzh%>&pagenum=<%=(pagenum-1)%> class="main">上一页</a>
<%Else%>
上一页
<%pagenum=1%>
<%End If%>
<%If pagenum < Trim(pagecount1) Then%>
<a href=<%=ipzh%>&pagenum=<%=(pagenum+1)%> class="main">下一页</a>
<%Else%>
下一页
<%pagenum=pagecount1%>
<%End If%>
<a href=<%=ipzh%>&pagenum=<%=pagecount1%> class="main">尾页</a>]
[页次:<%=pagenum%>/<%=pagecount1%>页] [每页显示<%=rs.pagesize%>条记录/总共<%=rs.recordcount%>条记录]
<%end if%>
</td>

<td width="133" height="30" class="link_1">本页合计:<%=mn%>元</td>
<%rs.close%>
usershuai 2007-09-06
  • 打赏
  • 举报
回复
还有就是 sum 不能用 order by
usershuai 2007-09-06
  • 打赏
  • 举报
回复
你把 # 号换成 '号试一下
ahsteven 2007-09-06
  • 打赏
  • 举报
回复
原始的语句如下:我想在下面的SQL语句中增加 SUM() 求某个字段货币的总价?请高手帮忙!谢谢!

<%
set rc=server.CreateObject("adodb.Recordset")
if Cus = "all" then
sql="Select * from TTR_Stock where S_date>=#"&start1&"# and S_date<=#"&end1&"# order by S_date Desc"
else
sql="Select * from TTR_Stock where S_date>=#"&start1&"# and S_date<=#"&end1&"# and Consignor='"&Cus&"'order by S_date Desc"
Response.write(sql)
end if
rc.open sql,conn,1,1
sum=0
rc.pagesize=19
dim Page
Page =1
if request("Page") <> "" then
Page=cint(request("Page"))
end if
if not rc.eof and not rc.bof then
rc.absolutepage=Page
end if
count=rc.pagesize

do while not rc.eof and count>0%>
bjweb 2007-09-06
  • 打赏
  • 举报
回复
moditime >= #"&fromdate&"# And moditime<= #"&enddate&"#

试试这种,应能解决
liangpei2008 2007-09-06
  • 打赏
  • 举报
回复
Response.write(sql)调试一下
ahsteven 2007-09-06
  • 打赏
  • 举报
回复
还是一样的错误呀?各们高手再帮帮忙!
谢谢!
ahsteven 2007-09-06
  • 打赏
  • 举报
回复
真的谢谢各位大侠,已经搞定了!谢谢!
ahsteven 2007-09-06
  • 打赏
  • 举报
回复
各位,那如果记录很多,而且分了很多页,怎样才能一次统计所有符合条件记录的总价钱?
谢谢了!
mailto520 2007-09-05
  • 打赏
  • 举报
回复
好像SUM不能和where联用

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧