0

由于在数据库中有一些记录的值为 Null,因此创建此代码以过滤在“rsActQty”或“rsSumQty”中未分配值的记录集。但是,无论我尝试什么,似乎这段代码都无法检测到 Null 值。而且我不知道我做错了什么。那你能给我一些建议吗?谢谢你。(这个数据库在 MSACCESS 中)

我想要的是: - 仅显示在“rsActQty”或“rsSumQty”中具有价值的记录。- 当此字段之一为 NULL 时,为其分配“0”。

<%
if Rs.eof then 
    response.write "<tr><td colspan=""6"">&nbsp;"
    call displayNotFoundRecord
    response.write "</td></tr>"
Else


Dim ActQty, sumQty, Total, rsActQty, rsSumQty, rsPdtn_qty_est, inv_date, res_date
    Do while Rs.AbsolutePage = strPageCurrent And Not Rs.EOF

        inv_id = rs.fields.item("inv_idRS")
        rsActQty = rs.fields.item("sumOfinv_qty_act")
        rsSumQty = rs.fields.item("SumOfres_qty")
        rsPdtn_qty_est = rs.fields.item("SumOfpdtn_qty_est")
        inv_date = rs.fields.item("inv_dateRS")
        res_date = rs.fields.item("res_dateRS")

            if rsActQty = "" then 
                ActQty = 0
            else
                ActQty = rsActQty
            end if

            if rsSumQty = "" then
                sumQty = 0
            else
                sumQty = rsSumQty
            end if 


        if rsActQty <> "" OR rsSumQty <> "" then

                if inv_date = "" then
                    dateshow = res_date
                else
                    dateshow =  inv_date
                end if

                if res_date = "" then
                    dateshow = res_date
                else
                    dateshow = res_date
                end if

                total = rs.fields.item("Total")
%>

<tr class='difcursor'> 
<td class="btline" width="25" align="center"><input type="checkbox" name="inv_id" value="<%=inv_id%>" onClick="highlightRow(this,'#FFFFCC','#EFF4FA');"></td>
<td class="btline" <%=genLink(inv_id)%> nowrap style="padding-right: 10px">&nbsp;<%=rs.fields.item("pd_id")%> </td>
<td class="btline" <%=genLink(inv_id)%> nowrap style="padding-right: 10px">&nbsp;<%=rs.fields.item("pd_name")%></td>
<td class="btline" <%=genLink(inv_id)%> nowrap style="padding-right: 10px">&nbsp;<%=PcsToDz(ActQty)%></td>
<td class="btline" <%=genLink(inv_id)%> nowrap style="padding-right: 10px">&nbsp;<%'=PcsToDz(rs.fields.item("SumOfpdtn_qty_est"))%></td>
<td class="btline" <%=genLink(inv_id)%> nowrap style="padding-right: 10px">&nbsp;<%=dateshow%></td>
<td class="btline" <%=genLink(inv_id)%> nowrap style="padding-right: 10px">&nbsp;<%=PcsToDz(sumQty)%></td>
<td class="btline" <%=genLink(inv_id)%> nowrap style="padding-right: 10px">&nbsp;<%=PcsTODz(Total)%></td>
<td class="btline"></td>
</tr>

<%
        end if

        Rs.movenext
    Loop
End if
Rs.close
set Rs=nothing
Call DBConnClose()
%>
4

2 回答 2

2

尝试使用 isNull 函数。例如

if not isNull(rs.fields.item("sumOfinv_qty_act")) then 
    ActQty = rs.fields.item("sumOfinv_qty_act")
else
    ActQty = 0
end if
于 2012-10-08T09:49:37.323 回答
1

Null 与空白值不同。

您可以尝试将 null 强制为字符串并进行比较:

    rsActQty = "" & rs.fields.item("sumOfinv_qty_act")
    rsSumQty = "" & rs.fields.item("SumOfres_qty")

您还可以在 sql 查询中处理 null ,例如:

select iif(isnull(fieldname),0,fieldname) as fieldname from table

这将为空值返回 0。

于 2012-10-08T10:02:21.313 回答