我正在使用 Classic ASP 从 SQL Server 2000 数据库中获取记录。这就是我使用的代码。
ASP 代码:
<form name="search" method="post" onsubmit="return attention();">
<table width="60%" border="0" cellpadding="2" cellspacing="0" style="margin:0 auto">
<tr>
    <td colspan="2"><h1 style="color:#003399;">Search for Certificate of Analysis</h1></td>
</tr>
<tr>
    <td valign="bottom">Product number <sup style="color:#EE0000;font-size:1.3em">*</sup></td>
    <td valign="bottom">Lot number</td>
</tr>
<tr>
    <td width="30%" valign="top">
        <input type="text" name="input1" size="20"/>
    </td>
    <td valign="top">
        <input type="text" size="20" name="input2"/> 
        <input style="background-color:#ffffff;border:0px;cursor:pointer" size="10" type="submit" name="sub" value=">>" />
    </td>
</tr>
</table>
<%
    if request.Form("sub") <> "" then
    Dim fname, lname
    fname= request.Form("input1")
    lname= request.Form("input2")
    session("n") = fname & lname
    sql = "Select * from search where cat_no_batch_no LIKE '"&request.Form("input1")&"%' OR cat_no_batch_no='"&session("n")&"'"
    rs.open sql, con, 1, 2
    if rs.eof then
    response.write("Please provide a valid Cat No.")    
    else
            do while not rs.eof
        %>
            <table border="1" cellpadding="5" cellspacing="0" width="60%" style="margin:0 auto; border-collapse:collapse;border-color:#999999">
            <tr>
                <td width="50%"><%=rs("cat_no_batch_no")%></td>
                <td width="10%">Click to open <a target="_blank" href="http://localhost/search1/<%=rs("pdf_path")%>"><%=rs("cat_no_batch_no")%></a></td>
            </tr>
            </table>
        <%
            rs.movenext
            loop
        end if
    rs.close
    end if
%>
</form>
上面的 LIKE 语句按预期工作,并显示包含类似 Cat No.的多条记录。当我在第一个输入框中输入Cat No并在另一个输入框中输入批号时,问题就出现了。我想要的输出应该只是显示一条记录,因为我已经给出了Cat No.和Lot Number,但它显示了多条记录。
我提供了更清晰的图像。
- 在下图中,我将6106021作为产品编号,因此它显示了两个条目。  
- 在这张图片中,我将6106021作为产品编号,将218111作为批号,它显示两个条目而不是 1。这就是问题所在,它应该显示一个条目,因为批号是唯一的,而猫号可以相同。 