注册 登录
编程论坛 ASP技术论坛

求助关于from 子句语法错误~

chfshe 发布于 2010-12-20 11:31, 1003 次点击
sql= "select g.goodsname,dd.sf from goods g,(select sum(allfees) as sf,goodsid from declarations where tag1=1 and tag2=1 and sendaddressid like '%"&customerid&"%' and reptime between #"&starttime&"# and #"&endtime&"# and goodsid="&goodsid&" group by goodsid)dd where dd.goodsid=g.goodsid "

请教一下大家这个语句哪里错了?我在ACCESS里面测试是正确的
麻烦大家了!
11 回复
#2
筱晓绾2010-12-20 11:42
那你现在用的是什么数据库啊?
&  #  这些符号在Sql Server里面不能用吧!目前我是没有用过...
#3
chfshe2010-12-20 12:01
回复 2楼 筱晓绾
用的是ACCESS的。就是加了goodsid="&goodsid&"后就出错了。是传值出错吗?
如果没有加这个的就没错
if goodsid="" then
sql= "select g.goodsname,dd.sf from goods g,(select sum(allfees) as sf,goodsid from declarations where tag1=1 and tag2=1 and sendaddressid like '%"&customerid&"%' and reptime between #"&starttime&"# and #"&endtime&"# group by goodsid) dd where dd.goodsid=g.goodsid "
else  
sql= "select g.goodsname,dd.sf from goods g,(select sum(allfees) as sf,goodsid from declarations where tag1=1 and tag2=1 and sendaddressid like '%"&customerid&"%' and reptime between #"&starttime&"# and #"&endtime&"# and goodsid="&goodsid&" group by goodsid)dd where dd.goodsid=g.goodsid "
end if
grs.open sql,conn,1,1
if 里面的没错。但是else的就有错了!
也不知道是不是传值传不过来~
可是下面这段没有错,那是否证明传值是正确的?
if goodsid="" then
sql= "select sum(allfees) as sf from declarations where tag1=1 and tag2=1 and sendaddressid like '%"&customerid&"%' and reptime between #"&starttime&"# and #"&endtime&"# "
else  
sql= "select sum(allfees) as sf from declarations where tag1=1 and tag2=1 and sendaddressid like '%"&customerid&"%' and reptime between #"&starttime&"# and #"&endtime&"# and goodsid="&goodsid
end if
#4
dzt00012010-12-20 12:13
写代码时要小心,不能用全角中文标点符号。
注意group by goodsid后的括号
#5
yms1232010-12-20 14:33
LZ输出一下你的SQL语句使用Access查询来测试一下就知道了
#6
hams2010-12-20 14:34
看得头晕,显示一下看看吧。
#7
chfshe2010-12-20 14:36
回复 5楼 yms123
我就是在ACCESS里面查询时是没有错误的!
#8
chfshe2010-12-20 14:39
回复 4楼 dzt0001
谢谢你,还是你比较细心!确实是你说的那里出错,改了就没事啦!
#9
yms1232010-12-20 14:39
以下是引用chfshe在2010-12-20 14:36:12的发言:

我就是在ACCESS里面查询时是没有错误的!
你查询的是ASP网页运行后的SQL语句?
#10
chfshe2010-12-20 14:46
回复 9楼 yms123
我也不知道怎么说,总之现在改了dzt0001说的地方就显示正确了!
#11
kira0072010-12-20 15:18
聚合函数 select sum(allfees) as sf 不能与其他搜索语句一起使用
#12
chfshe2010-12-21 08:13
回复 11楼 kira007
可以的啊,怎么不可以!
1