Ive created the folowing SQL (simple to all you)in MS Access
SELECT CatalogueNo, Manufacturer, PPM
FROM monochromea4
WHERE CatalogueNo LIKE 'varCatalogueNo' AND Manufacturer LIKE 'varManufacturer' AND PPM LIKE 'varPPM'
My data is simliar to
catalogueNo = E11-EPSB3006
Manufacturer = Epson 580
PPM (pages per minute)= 10
etc etc....
The question is how do I create a search where it will find the Printer if only "EPS" is entered for the catalogueNo. Or/And only epson is entered for the manufacturer (without the 580) with printer capable of producing 10 pages per minute
I have about 60 printers all together, eg Lexamrk, Brother, HP etc etc.
thanks for your help
So there are many search options eg LEX for Lexmark, Bro for Brother Etc, so is there any other way around this apart from entering all the possible codes, as I do not know what the user will search for?
Wardbekker's code looks like the solution you're after.
When using the LIKE filter in SQL you need to append a % symbol as a wildcard, so %EPS% means any text/varchar (etc..) field that has EPS in it somewhere which I think is the effect you're looking for.
So as you build your SQL string it should probably look something like:
"SELECT CatalogueNo, Manufacturer, PPM
FROM monochromea4
WHERE CatalogueNo LIKE '%" & varCatalogueNo & "%' AND Manufacturer LIKE '%" & varManufacturer & "%' AND PPM LIKE '%" & varPPM & "%'
Where the var variables are the users text input.
Josh
This is my code
Recordset1.Source = "SELECT CatalogueNo, Manufacturer, PPM FROM monochromea4 WHERE CatalogueNo LIKE '%" & Recordset1__varCatalogueNo & "%' AND Manufacturer LIKE '%" & Recordset1__varManufacturer & "%' AND PPM LIKE '%" & Recordset1__varPPM & "%'";
and the error is
Microsoft JScript compilation error '800a03ec'
Expected ';'
/results.asp, line 24
Recordset1.Source = SELECT CatalogueNo, Manufacturer, PPM FROM monochromea4 WHERE CatalogueNo LIKE '%" & Recordset1__varCatalogueNo & "%' AND Manufacturer LIKE '%" & Recordset1__varManufacturer & "%' AND PPM LIKE '%" & Recordset1__varPPM & "%';
sorry, but im fairly new to SQL, im also using dreamweaver Ultradev4 if it help?
I now get this error:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC Microsoft Access Driver] Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.
/results.asp, line 28
any ideas
Sorry to be a pain, but once i get the basic template Im sure I'll be OK for future queries like this
<%@LANGUAGE="JAVASCRIPT"%>
<!--#include file="Connections/quote.asp" -->
<%
var Recordset1__varCatalogueNo = "%";
if(String(Request("textCatalogueNo")) != "undefined") {
Recordset1__varCatalogueNo = String(Request("textCatalogueNo"));
}
%>
<%
var Recordset1__varManufacturer = "%";
if(String(Request("textManufacturer")) != "undefined") {
Recordset1__varManufacturer = String(Request("textManufacturer"));
}
%>
<%
var Recordset1__varPPM = "%";
if(String(Request("textPPM")) != "undefined") {
Recordset1__varPPM = String(Request("textPPM"));
}
%>
<%
var Recordset1 = Server.CreateObject("ADODB.Recordset");
Recordset1.ActiveConnection = MM_quote_STRING;
Recordset1.Source = "SELECT CatalogueNo, Manufacturer, PPM FROM monochromea4 WHERE CatalogueNo LIKE '%" + Recordset1__varCatalogueNo + "%' AND Manufacturer LIKE '%" + Recordset1__varManufacturer + "%' AND PPM LIKE '%" + Recordset1__varPPM & "%'";
Recordset1.CursorType = 0;
Recordset1.CursorLocation = 2;
Recordset1.LockType = 3;
Recordset1.Open();
var Recordset1_numRows = 0;
%>
var sSQL = "SELECT CatalogueNo, Manufacturer, PPM FROM monochromea4 WHERE CatalogueNo LIKE '%" + Recordset1__varCatalogueNo + "%' AND Manufacturer LIKE '%" + Recordset1__varManufacturer + "%' AND PPM LIKE '%" + Recordset1__varPPM & "%'";
Response.Write sSQL
Response.End
Then when you've sussed it you can just remove the last two lines and set you recordset1.source = sSQL
Make sense?
Let Dreamweaver write the basic code, then you go in and simplify it.
For instance, DW always defines variables as follows: Recordset1__varPPM
you can manipulate it just to varPPM or even PPM . then, when you are studying your code for syntax you can actually see where the variables are.
Start simple, as described above. Then add variables one at a time until it breaks.
The "recordset1.source" is a variable you can use to print to your screen within the delimiters.
But the basic principle is correct.
Recordset1.source = "SELECT * FROM monochromea4"; ..this worked and displayed all records
so I know all the connection are correct, which is a good start..
Next i tried
Recordset1.source = "SELECT * FROM monochromea4 WHERE CatalogueNo LIKE '%EPS%' OR Manufacturer LIKE '%epson%' AND PPM = 10";
this showed all Catalogue Numbers with EPS in it, but ignored the Manufactuer and PPM as it showed some lexmark printers and some pages at 12 ppm. - but no errors..
Next
Recordset1.source = "SELECT * FROM monochromea4 WHERE CatalogueNo LIKE '%" + Recordset1__varCatalogueNo + "%';
but this time an ERROR!!
Microsoft JScript compilation error '800a03f7'
Unterminated string constant
/results.asp, line 31
Recordset1.source = "SELECT * FROM monochromea4 WHERE CatalogueNo LIKE '%" + Recordset1__varCatalogueNo + "%';
any ideas
but all your help has been appreciated, and your right starting from basics is better, and I will change my variables so they are easier to read.
However a few tests have showed that if i enter Lexmark with 20 ppm it works fine.
But if i enter Lexmark with 60 ppm (which there are no 60 ppm in the database)
I get this error
ADODB.Field error '800a0bcd'
Either BOF or EOF is True, or the current record has been deleted; the operation requested by the application requires a current record.
/results.asp, line 231
could you lead me down the right path on this problem
thanks
again