Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

SQL query with AND or OR

New Here ,
Feb 24, 2010 Feb 24, 2010

Hi,

I am trying to get a recordset that samples multiple columns of my Access database for filtering, rather than just one.  I looked at a few .asp websites and they say the query would be written like this:

SELECT SystemName, SystemCategory, Branch, Manufacturer

FROM UnmmannedAircraftSystems

WHERE Branch LIKE %MMColParam%

AND PerfSensorPayloads LIKE %MMColParam2%

ORDER BY SystemName ASC

but it never works.  The page fails on the server.  And I know this type of query works through straight .asp coding, but somehow the way Dreamweaver sets up the variables is killing it.

Anybody have an ideas?

MW

TOPICS
Server side applications
468
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 24, 2010 Feb 24, 2010

>The page fails on the server.

Fails in what way? And you will need to include more code so we can see how the parameters are being populated.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 24, 2010 Feb 24, 2010

Instead of the recordset data loading in the table cell, I get this:

ADODB.Fields error '800a0cc1'

Item cannot be found in the collection corresponding to the requested name or ordinal.

/Connections/MultipleRecordFilt.asp, line 203

MW

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 24, 2010 Feb 24, 2010

SQLcap.jpgThe first page has a form with 2 select menus and a submit button.  Upon selection and submission, the action of the form loads the page that is currently failing.  The form variables are passed into the target page which attempts to create a record set that is filtered from the 2 previous select menu pages.  Here is a screencap from the 2nd page's Dreamweaver recordset:

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 24, 2010 Feb 24, 2010

Screen shots don't really help.We need to see the code in /Connections/MultipleRecordFilt.asp

and highlight line 203. My guess is that you are referencing an object that doesn't exist somewhere after you retrieve the recordset.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2010 Feb 25, 2010

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../../Connections/BleahBleahBleahhhhh" -->
<%
Dim RSfilterRec__MMColParam
RSfilterRec__MMColParam = "1"
If (Request.Form("BranchesUsedby") <> "") Then
  RSfilterRec__MMColParam = Request.Form("BranchesUsedby")
End If
%>
<%
Dim RSfilterRec__MMColParam2
RSfilterRec__MMColParam2 = "1"
If (Request.Form("SensorPay") <> "") Then
  RSfilterRec__MMColParam2 = Request.Form("SensorPay")
End If
%>
<%
Dim RSfilterRec
Dim RSfilterRec_cmd
Dim RSfilterRec_numRows

Set RSfilterRec_cmd = Server.CreateObject ("ADODB.Command")
RSfilterRec_cmd.ActiveConnection = MM_ConnUASdata_STRING
RSfilterRec_cmd.CommandText = "SELECT SystemName, SystemCategory, Branch, Manufacturer FROM UnmannedAircraftSystems WHERE Branch LIKE ? AND PerfSensorsPayloads LIKE ? ORDER BY SystemName ASC"
RSfilterRec_cmd.Prepared = true
RSfilterRec_cmd.Parameters.Append RSfilterRec_cmd.CreateParameter("param1", 200, 1, 255, "%" + RSfilterRec__MMColParam + "%") ' adVarChar
RSfilterRec_cmd.Parameters.Append RSfilterRec_cmd.CreateParameter("param2", 200, 1, 255, "%" + RSfilterRec__MMColParam2 + "%") ' adVarChar

Set RSfilterRec = RSfilterRec_cmd.Execute
RSfilterRec_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = 10
Repeat1__index = 0
RSfilterRec_numRows = RSfilterRec_numRows + Repeat1__numRows
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="head" -->
<!-- TemplateEndEditable -->
<style type="text/css">
<!--
body  {
font: 100% Verdana, Arial, Helvetica, sans-serif;
background: #666666;
margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
padding: 0;
text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
color: #000000;
}

/* Tips for Elastic layouts
1. Since the elastic layouts overall sizing is based on the user's default fonts size, they are more unpredictable. Used correctly, they are also more accessible for those that need larger fonts size since the line length remains proportionate.
2. Sizing of divs in this layout are based on the 100% font size in the body element. If you decrease the text size overall by using a font-size: 80% on the body element or the #container, remember that the entire layout will downsize proportionately. You may want to increase the widths of the various divs to compensate for this.
3. If font sizing is changed in differing amounts on each div instead of on the overall design (ie: #sidebar1 is given a 70% font size and #mainContent is given an 85% font size), this will proportionately change each of the divs overall size. You may want to adjust based on your final font sizing.
*/
.thrColEls #container {
width: 46em;  /* this width will create a container that will fit in an 800px browser window if text is left at browser default font sizes */
background: #FFFFFF;
margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
border: 1px solid #000000;
text-align: left; /* this overrides the text-align: center on the body element. */
}

/* Tips for sidebar1:
1. Be aware that if you set a font-size value on this div, the overall width of the div will be adjusted accordingly.
2. Since we are working in ems, it's best not to use padding on the sidebar itself. It will be added to the width for standards compliant browsers creating an unknown actual width.
3. Space between the side of the div and the elements within it can be created by placing a left and right margin on those elements as seen in the ".thrColEls #sidebar1 p" rule.
*/
.thrColEls #sidebar1 {
float: left;
width: 11em; /* since this element is floated, a width must be given */
background: #EBEBEB; /* top and bottom padding create visual space within this div */
height: 1200px;
padding-top: 15px;
padding-right: 0;
padding-bottom: 15px;
padding-left: 0;
}
.thrColEls #sidebar2 {
float: right;
width: 11em; /* since this element is floated, a width must be given */
background: #EBEBEB; /* the background color will be displayed for the length of the content in the column, but no further */
padding: 15px 0; /* top and bottom padding create visual space within this div */
height: 1200px;
}
.thrColEls #sidebar1 h3, .thrColEls #sidebar1 p, .thrColEls #sidebar2 p, .thrColEls #sidebar2 h3 {
margin-left: 10px; /* the left and right margin should be given to every element that will be placed in the side columns */
margin-right: 10px;
height: 100%;
}

/* Tips for mainContent:
1. If you give this #mainContent div a font-size value different than the #sidebar1 div, the margins of the #mainContent div will be based on its font-size and the width of the #sidebar1 div will be based on its font-size. You may wish to adjust the values of these divs.
2. The space between the mainContent and sidebar1 is created with the left margin on the mainContent div.  No matter how much content the sidebar1 div contains, the column space will remain. You can remove this left margin if you want the #mainContent div's text to fill the #sidebar1 space when the content in #sidebar1 ends.
3. To avoid float drop, you may need to test to determine the approximate maximum image/element size since this layout is based on the user's font sizing combined with the values you set. However, if the user has their browser font size set lower than normal, less space will be available in the #mainContent div than you may see on testing.
4. In the Internet Explorer Conditional Comment below, the zoom property is used to give the mainContent "hasLayout." This avoids several IE-specific bugs that may occur.
*/
.thrColEls #mainContent {
  margin: 0 12em 0 12em; /* the right margin can be given in ems or pixels. It creates the space down the right side of the page. */
}

/* Miscellaneous classes for reuse */
.fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
float: right;
margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page */
float: left;
margin-right: 8px;
}
.clearfloat { /* this class should be placed on a div or break element and should be the final element before the close of a container that should fully contain a float */
clear:both;
    height:0;
    font-size: 1px;
    line-height: 0px;
}
-->
</style><!--[if IE]>
<style type="text/css">
/* place css fixes for all versions of IE in this conditional comment */
.thrColEls #sidebar1, .thrColEls #sidebar2 { padding-top: 30px; }
.thrColEls #mainContent { zoom: 1; padding-top: 15px; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]--></head>

<body class="thrColEls">

<div id="container">
  <div id="sidebar1">
    <h3> </h3>
    <!-- end #sidebar1 --></div>
  <div id="sidebar2">
    <h3> </h3>
    <!-- end #sidebar2 --></div>
  <div id="mainContent">
    <h1> 
      <table border="1">
        <tr>
          <td>ID</td>
          <td>SystemName</td>
          <td>SystemCategory</td>
          <td>Branch</td>
          <td>Manufacturer</td>
          <td>Status</td>
          <td>Inventory</td>
          <td>PlatformCost</td>
          <td>SystemCost</td>
          <td>PlannedBuyToDate</td>
          <td>PlannedBuyYear1</td>
          <td>PlannedBuyYear1Quantity</td>
          <td>PlannedBuyYear2</td>
          <td>PlannedBuyYear2Quantity</td>
          <td>PlannedBuyYear3</td>
          <td>PlannedBuyYear3Quantity</td>
          <td>PlannedBuyYear4</td>
          <td>PlannedBuyYear4Quantity</td>
          <td>PlannedBuyYear5</td>
          <td>PlannedBuyYear5Quantity</td>
          <td>PlannedBuyYear6</td>
          <td>PlannedBuyYear6Quantity</td>
          <td>PlannedBuyYear7</td>
          <td>PlannedBuyYear7Quantity</td>
          <td>PlannedBuyYear8</td>
          <td>PlannedBuyYear8Quantity</td>
          <td>PlaformOperationPicLink</td>
          <td>OrthoDrawingLink</td>
          <td>Capability</td>
          <td>BackgroundSysDescrip</td>
          <td>SystemDescription</td>
          <td>CharLength</td>
          <td>CharWingSpan</td>
          <td>CharGrossWgt</td>
          <td>CharPayloadWgt</td>
          <td>CharEngines</td>
          <td>CharFuelWgtType</td>
          <td>DataLinks1</td>
          <td>DataLinks2</td>
          <td>DataLinks3</td>
          <td>Frequencies1</td>
          <td>Frequencies2</td>
          <td>Frequencies3</td>
          <td>PerfEndurance</td>
          <td>PerfRadius</td>
          <td>PerfCeiling</td>
          <td>PerfAirspeeds</td>
          <td>PerfTakeoff</td>
          <td>PerfLanding</td>
          <td>PerfSensorsPayloads</td>
          <td>PerfSensorModels</td>
          <td>PayloadCharInternalSize</td>
          <td>PayloadCharInternalWgt</td>
          <td>PayloadCharInternalPwr</td>
          <td>PayloadCharInternalEnv</td>
          <td>PayloadCharExternalSize</td>
          <td>PayloadCharExternalWgt</td>
          <td>PayloadCharExternalPwr</td>
          <td>PayloadCharExternalEnv</td>
        </tr>
        <% While ((Repeat1__numRows <> 0) AND (NOT RSfilterRec.EOF)) %>
          <tr>
            <td><%=(RSfilterRec.Fields.Item("ID").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("SystemName").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("SystemCategory").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("Branch").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("Manufacturer").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("Status").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("Inventory").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PlatformCost").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("SystemCost").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PlannedBuyToDate").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PlannedBuyYear1").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PlannedBuyYear1Quantity").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PlannedBuyYear2").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PlannedBuyYear2Quantity").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PlannedBuyYear3").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PlannedBuyYear3Quantity").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PlannedBuyYear4").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PlannedBuyYear4Quantity").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PlannedBuyYear5").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PlannedBuyYear5Quantity").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PlannedBuyYear6").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PlannedBuyYear6Quantity").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PlannedBuyYear7").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PlannedBuyYear7Quantity").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PlannedBuyYear8").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PlannedBuyYear8Quantity").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PlaformOperationPicLink").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("OrthoDrawingLink").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("Capability").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("BackgroundSysDescrip").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("SystemDescription").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("CharLength").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("CharWingSpan").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("CharGrossWgt").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("CharPayloadWgt").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("CharEngines").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("CharFuelWgtType").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("DataLinks1").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("DataLinks2").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("DataLinks3").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("Frequencies1").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("Frequencies2").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("Frequencies3").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PerfEndurance").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PerfRadius").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PerfCeiling").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PerfAirspeeds").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PerfTakeoff").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PerfLanding").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PerfSensorsPayloads").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PerfSensorModels").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PayloadCharInternalSize").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PayloadCharInternalWgt").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PayloadCharInternalPwr").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PayloadCharInternalEnv").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PayloadCharExternalSize").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PayloadCharExternalWgt").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PayloadCharExternalPwr").Value)%></td>
            <td><%=(RSfilterRec.Fields.Item("PayloadCharExternalEnv").Value)%></td>
          </tr>
          <%
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  RSfilterRec.MoveNext()
Wend
%>
      </table>
    </h1>
    <!-- end #mainContent --></div>
<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
<!-- end #container --></div>
</body>
</html>
<%
RSfilterRec.Close()
Set RSfilterRec = Nothing
%>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2010 Feb 25, 2010

Okay, now it is saying this:

ADODB.Fields error '800a0cc1'

Item cannot be found in the collection corresponding to the requested name or ordinal.

/connections/MultipleRecordFilt.asp, line 211

Line 211 happens to be this:

<td><%=(RSfilterRec.Fields.Item("ID").Value)%></td>

which is the ID column in my Access database, and the first recordset line.

What the heck?   It's saying my ID column doesn't exist?

MW

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2010 Feb 25, 2010

Well, I got the 'test' feature of the recordset to work...as it turns out the

database value was spelled with a space (Air Force) and the

pulldown value was spelled without a space (Airforce)

Ugggggg

HOWEVER, the Multiplerecordfilt.asp page, even though the recordset test works in Dreamweaver, still fails to load online properly, popping the line 211 error into the dynamic table on page load.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2010 Feb 25, 2010
LATEST

Okay,

I needed to add a 'hide if recordset is empty' to the dynamic data

field, and now the AND clause is totally working.  The problem was all

grammatical glitches with the database not equalling the passed for variable values perfectly, however this is strange in itself because I had used a 'LIKE' clause, setting the filter options to 'CONTAINS' rather than '=' so I figured spelling and caps wouldn't be such an issue, but apparently it has to contain the complete string, so the space in Air Force horked everything up.

Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines