Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 Where cluase accessing multiple columns

Author  Topic 

mkusza1
Starting Member

12 Posts

Posted - 2008-01-22 : 08:36:27
Here's the code from my web page. Its in asp using javascript. I have an Access Database where my information is contained. I am however having several issues. First issue is that i have multiple columns that i need to have searched. Everything works fine when my WHERE [Column] LIKE ? (The question mark is %MMColParam% which always get replaced with the ?)but when i try WHERE [Column] LIKE ? or [Column1] LIKE ? it gives me a syntax error or wont search for whats entered into the search field. The way i visualize the code would read IF then else statement. If it finds in first column no need to look in next column if not found in first column go to next column using IF THEN ElSE logic. Not sure how to accomplish that and am hoping you guys/gals can help. I highleted whats pertinent to this question.Thanks


<%@LANGUAGE="JAVASCRIPT"%>
<!--#include virtual="/sysdcg/Connections/Products.asp" -->
<%
var rsCatalog__MMColParam = "1";
if (String(Request.Form("searchText")) != "undefined" &&
String(Request.Form("searchText")) != "") {
rsCatalog__MMColParam = String(Request.Form("searchText"));
}
%>
<%
var rsCatalog_cmd = Server.CreateObject ("ADODB.Command");
rsCatalog_cmd.ActiveConnection = MM_Products_STRING;
rsCatalog_cmd.CommandText = "SELECT [Application], [Section], [Part Number], [Description], [Part Code], [Revision] FROM Catalog WHERE [Part Code] LIKE ? ORDER BY [Application] ASC";
rsCatalog_cmd.Prepared = true;
rsCatalog_cmd.Parameters.Append(rsCatalog_cmd.CreateParameter("param1", 200, 1, 50, "%" + rsCatalog__MMColParam + "%")); // adVarChar

var rsCatalog = rsCatalog_cmd.Execute();
var rsCatalog_numRows = 0;
%>

<%
var Repeat1__numRows = 10;
var Repeat1__index = 0;
rsCatalog_numRows += Repeat1__numRows;
%>
<%
// *** Recordset Stats, Move To Record, and Go To Record: declare stats variables

// set the record count
var rsCatalog_total = rsCatalog.RecordCount;

// set the number of rows displayed on this page
if (rsCatalog_numRows < 0) { // if repeat region set to all records
rsCatalog_numRows = rsCatalog_total;
} else if (rsCatalog_numRows == 0) { // if no repeat regions
rsCatalog_numRows = 1;
}

// set the first and last displayed record
var rsCatalog_first = 1;
var rsCatalog_last = rsCatalog_first + rsCatalog_numRows - 1;

// if we have the correct record count, check the other stats
if (rsCatalog_total != -1) {
rsCatalog_numRows = Math.min(rsCatalog_numRows, rsCatalog_total);
rsCatalog_first = Math.min(rsCatalog_first, rsCatalog_total);
rsCatalog_last = Math.min(rsCatalog_last, rsCatalog_total);
}
%>
<% var MM_paramName = ""; %>
<%
// *** Move To Record and Go To Record: declare variables

var MM_rs = rsCatalog;
var MM_rsCount = rsCatalog_total;
var MM_size = rsCatalog_numRows;
var MM_uniqueCol = "";
MM_paramName = "";
var MM_offset = 0;
var MM_atTotal = false;
var MM_paramIsDefined = (MM_paramName != "" && String(Request(MM_paramName)) != "undefined");
%>
<%
// *** Move To Record: handle 'index' or 'offset' parameter

if (!MM_paramIsDefined && MM_rsCount != 0) {

// use index parameter if defined, otherwise use offset parameter
r = String(Request("index"));
if (r == "undefined") r = String(Request("offset"));
if (r && r != "undefined") MM_offset = parseInt(r);

// if we have a record count, check if we are past the end of the recordset
if (MM_rsCount != -1) {
if (MM_offset >= MM_rsCount || MM_offset == -1) { // past end or move last
if ((MM_rsCount % MM_size) != 0) { // last page not a full repeat region
MM_offset = MM_rsCount - (MM_rsCount % MM_size);
} else {
MM_offset = MM_rsCount - MM_size;
}
}
}

// move the cursor to the selected record
for (var i=0; !MM_rs.EOF && (i < MM_offset || MM_offset == -1); i++) {
MM_rs.MoveNext();
}
if (MM_rs.EOF) MM_offset = i; // set MM_offset to the last possible record
}
%>
<%
// *** Move To Record: if we dont know the record count, check the display range

if (MM_rsCount == -1) {

// walk to the end of the display range for this page
for (var i=MM_offset; !MM_rs.EOF && (MM_size < 0 || i < MM_offset + MM_size); i++) {
MM_rs.MoveNext();
}

// if we walked off the end of the recordset, set MM_rsCount and MM_size
if (MM_rs.EOF) {
MM_rsCount = i;
if (MM_size < 0 || MM_size > MM_rsCount) MM_size = MM_rsCount;
}

// if we walked off the end, set the offset based on page size
if (MM_rs.EOF && !MM_paramIsDefined) {
if ((MM_rsCount % MM_size) != 0) { // last page not a full repeat region
MM_offset = MM_rsCount - (MM_rsCount % MM_size);
} else {
MM_offset = MM_rsCount - MM_size;
}
}

// reset the cursor to the beginning
if (MM_rs.CursorType > 0) {
if (!MM_rs.BOF) MM_rs.MoveFirst();
} else {
MM_rs.Requery();
}

// move the cursor to the selected record
for (var i=0; !MM_rs.EOF && i < MM_offset; i++) {
MM_rs.MoveNext();
}
}
%>
<%
// *** Move To Record: update recordset stats

// set the first and last displayed record
rsCatalog_first = MM_offset + 1;
rsCatalog_last = MM_offset + MM_size;
if (MM_rsCount != -1) {
rsCatalog_first = Math.min(rsCatalog_first, MM_rsCount);
rsCatalog_last = Math.min(rsCatalog_last, MM_rsCount);
}

// set the boolean used by hide region to check if we are on the last record
MM_atTotal = (MM_rsCount != -1 && MM_offset + MM_size >= MM_rsCount);
%>
<%
// *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

// create the list of parameters which should not be maintained
var MM_removeList = "&index=";
if (MM_paramName != "") MM_removeList += "&" + MM_paramName.toLowerCase() + "=";
var MM_keepURL="",MM_keepForm="",MM_keepBoth="",MM_keepNone="";

// add the URL parameters to the MM_keepURL string
for (var items=new Enumerator(Request.QueryString); !items.atEnd(); items.moveNext()) {
var nextItem = "&" + items.item().toLowerCase() + "=";
if (MM_removeList.indexOf(nextItem) == -1) {
MM_keepURL += "&" + items.item() + "=" + Server.URLencode(Request.QueryString(items.item()));
}
}

// add the Form variables to the MM_keepForm string
for (var items=new Enumerator(Request.Form); !items.atEnd(); items.moveNext()) {
var nextItem = "&" + items.item().toLowerCase() + "=";
if (MM_removeList.indexOf(nextItem) == -1) {
MM_keepForm += "&" + items.item() + "=" + Server.URLencode(Request.Form(items.item()));
}
}

// create the Form + URL string and remove the intial '&' from each of the strings
MM_keepBoth = MM_keepURL + MM_keepForm;
if (MM_keepBoth.length > 0) MM_keepBoth = MM_keepBoth.substring(1);
if (MM_keepURL.length > 0) MM_keepURL = MM_keepURL.substring(1);
if (MM_keepForm.length > 0) MM_keepForm = MM_keepForm.substring(1);
%>
<%
// *** Move To Record: set the strings for the first, last, next, and previous links

var MM_moveFirst="",MM_moveLast="",MM_moveNext="",MM_movePrev="";
var MM_keepMove = MM_keepBoth; // keep both Form and URL parameters for moves
var MM_moveParam = "index";

// if the page has a repeated region, remove 'offset' from the maintained parameters
if (MM_size > 1) {
MM_moveParam = "offset";
if (MM_keepMove.length > 0) {
params = MM_keepMove.split("&");
MM_keepMove = "";
for (var i=0; i < params.length; i++) {
var nextItem = params[i].substring(0,params[i].indexOf("="));
if (nextItem.toLowerCase() != MM_moveParam) {
MM_keepMove += "&" + params[i];
}
}
if (MM_keepMove.length > 0) MM_keepMove = MM_keepMove.substring(1);
}
}

// set the strings for the move to links
if (MM_keepMove.length > 0) MM_keepMove = Server.HTMLEncode(MM_keepMove) + "&";
var urlStr = Request.ServerVariables("URL") + "?" + MM_keepMove + MM_moveParam + "=";
MM_moveFirst = urlStr + "0";
MM_moveLast = urlStr + "-1";
MM_moveNext = urlStr + (MM_offset + MM_size);
MM_movePrev = urlStr + Math.max(MM_offset - MM_size,0);
%>

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-01-22 : 08:40:39
What do

Debug.Print rsCatalog_cmd.CommandText give?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

mkusza1
Starting Member

12 Posts

Posted - 2008-01-22 : 08:55:52
Microsoft JScript compilation error '800a03ec'

Expected ';'

/sysdcg/ASP/jblsearchtest.asp, line 13

Debug.Print rsCatalog_cmd.CommandText = "SELECT [Application], [Section], [Part Number], [Description], [Part Code], [Revision] FROM Catalog WHERE [Part Code] LIKE ? ORDER BY [Application] ASC";
------------^
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-01-22 : 11:26:01
I am confused. You have code highlighted in red, and it isn't what you described that you are trying to do that gives you the error. Does the code you've shown us that is highlighted in red work or not?

As a rule of thumb, if you have multiple ? placeholders in an oledb command, you must also have a matching number of parameters -- even if they are the same value.


- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

mkusza1
Starting Member

12 Posts

Posted - 2008-01-22 : 11:37:50
Original
<%
var rsCatalog__MMColParam = "1";
if (String(Request.Form("searchText")) != "undefined" &&
String(Request.Form("searchText")) != "") {
rsCatalog__MMColParam = String(Request.Form("searchText"));
}
%>
<%
var rsCatalog_cmd = Server.CreateObject ("ADODB.Command");
rsCatalog_cmd.ActiveConnection = MM_Products_STRING;
rsCatalog_cmd.CommandText = "SELECT [Application], [Section], [Part Number], [Description], [Part Code], [Revision] FROM Catalog WHERE [Part Code] LIKE ? ORDER BY [Application] ASC";
rsCatalog_cmd.Prepared = true;
rsCatalog_cmd.Parameters.Append(rsCatalog_cmd.CreateParameter("param1", 200, 1, 50, "%" + rsCatalog__MMColParam + "%")); // adVarChar

var rsCatalog = rsCatalog_cmd.Execute();
var rsCatalog_numRows = 0;
%>


Edited

<%
var rsCatalog__MMColParam = "1,2,3";
if (String(Request.Form("searchText")) != "undefined" &&
String(Request.Form("searchText")) != "") {
rsCatalog__MMColParam = String(Request.Form("searchText"));
}
%>
<%
var rsCatalog_cmd = Server.CreateObject ("ADODB.Command");
rsCatalog_cmd.ActiveConnection = MM_Products_STRING;
rsCatalog_cmd.CommandText = "SELECT [Application], [Section], [Part Number], [Description], [Part Code], [Revision] FROM Catalog WHERE [Part Code] LIKE ? OR [Application] LIKE ? OR [Section] LIKE ? ORDER BY [Application] ASC";
rsCatalog_cmd.Prepared = true;
rsCatalog_cmd.Parameters.Append(rsCatalog_cmd.CreateParameter("param1", 200, 1, 50, "%" + rsCatalog__MMColParam + "%")); // adVarChar
rsCatalog_cmd.Parameters.Append(rsCatalog_cmd.CreateParameter("param2", 200, 1, 50, "%" + rsCatalog__MMColParam + "%")); // adVarChar
rsCatalog_cmd.Parameters.Append(rsCatalog_cmd.CreateParameter("param3", 200, 1, 50, "%" + rsCatalog__MMColParam + "%")); // adVarChar




Would this be what you are saying to do JSmith? I believe i coded it right.

Everything is working correctly there so yea next question. Should i just start a new post or continue on this one?
Go to Top of Page
   

- Advertisement -