呵呵,不要尾部的len([flbh])=7这个条件就可以了。不过需要在输入时确定一个规则,凡是有下一级数据的,本级都保持为0或者null。如果不按照这个规则的话,数据都统计重复了。
SELECT ht_flxz.*, IIf(([ysje] is null) or ([ysje]=0),DSum("ysje","ht_flxz","flbh like '" & [flbh] & "*'"),[ysje]) AS Sumysje
FROM ht_flxz
ORDER BY ht_flxz.flbh;
SELECT ht_flxz.*, IIf(([ysje] is null) or ([ysje]=0),DSum("ysje","ht_flxz","flbh like '" & [flbh] & "*' and len(flbh)=7"),[ysje]) AS Sumysje
FROM ht_flxz
ORDER BY ht_flxz.flbh;
todaynew 发表于 2011-10-27 19:22
SELECT ht_flxz.*, IIf(nz([ysje],0)0,[ysje],DSum("ysje","ht_flxz","flbh like '" & [flbh] & "*' an ...
你好~~~
我查了很多资料才有点明白,ASP不支持NZ这个函数我想能否用isnull来代替呢?
我用isnull来替代,代码如下
SELECT ht_flxz.*, IIf(isnull([ysje]),[ysje],DSum("ysje","ht_flxz","flbh like '" & [flbh] & "*' and len(flbh)=7")) AS Sumysje
FROM ht_flxz
ORDER BY ht_flxz.flbh;
todaynew 发表于 2011-10-27 19:22
SELECT ht_flxz.*, IIf(nz([ysje],0)0,[ysje],DSum("ysje","ht_flxz","flbh like '" & [flbh] & "*' an ...
谢谢你!~~~
但有个问题让我纳闷了!
我用ASP网页代码读取表时,提示这样的错误~
Microsoft OLE DB Provider for ODBC Drivers '80040e14'
[Microsoft][ODBC Microsoft Access Driver] 表达式中 'nz' 函数未定义。
\htxt\xxx.asp, line 8
ASP网页代码为
<%
dim conn
dim connstr
connstr="DBQ="+server.mappath("../data.mdb")+";DefaultDir=;DRIVER={Driver do Microsoft Access (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
set rs=server.createobject("adodb.recordset")
rs.open "select * from ht_flxz_aa",conn,1,3
Do Until rs.EOF
Response.Write rs("flxz")&"<br/>"
rs.MoveNext
Loop
response.write rs
rs.close
conn.close
set rs=nothing
set con=nothing
%>
是什么原因呢?