473,385 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Syntax for wildcard query in ASP 3.0

This is my query named "spVOC_Sp_Example_search" in Access 2003:

PARAMETERS [pSearch] Text ( 255 );
SELECT Example.Example
FROM Example
WHERE (((Example.Example) Like "*" & [pSearch] & "*"));

It works great: I call the query, am prompted for the pSearch param value,
I supply a string as the value, and it returns all records with that string
contained anyhwere in the "example" field.

But none of the queries below will work in ASP 3.0:

Set rs = Server.CreateObject("ADODB.recordset")

sSQL="spVOC_Sp_Example_search pSearch=%a%"
sSQL="spVOC_Sp_Example_search pSearch=*"
sSQL="spVOC_Sp_Example_search pSearch=%"
sSQL="spVOC_Sp_Example_search pSearch='a'"
sSQL="spVOC_Sp_Example_search pSearch=""a"""
sSQL="spVOC_Sp_Example_search a"
sSQL="spVOC_Sp_Example_search *a*"
sSQL="spVOC_Sp_Example_search %a%"
sSQL="spVOC_Sp_Example_search %"
sSQL="spVOC_Sp_Example_search *"
sSQL="spVOC_Sp_Example_search ''"
rs.Open sSQL, cn, 0, 4

i=rs.RecordCount
All of the queries above either return 0 records or error out (Invalid SQL
statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.)

How do I properly call an Access parameterized wildcard query from ASP?
Mar 25 '07 #1
4 6488
Dave wrote:
This is my query named "spVOC_Sp_Example_search" in Access 2003:

PARAMETERS [pSearch] Text ( 255 );
SELECT Example.Example
FROM Example
WHERE (((Example.Example) Like "*" & [pSearch] & "*"));
How do I properly call an Access parameterized wildcard query from
ASP?
In order to call the query via ADO, you must change the Jet wildcards to
ODBc wildcards:

WHERE (((Example.Example) Like "%" & [pSearch] & "%"));

Then you can simply call it by:

set rs=createobject("adodb.recordset")
cn.spVOC_Sp_Example_search "a", rs

See:
http://www.google.com/groups?hl=en&l...TNGP12.phx.gbl

http://groups.google.com/groups?hl=e...tngp13.phx.gbl
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Mar 25 '07 #2
Thanks Bob

I think there is something fundamental I'm missing here.

I am not using dynamic SQL, my query resides on Access so in the Access
application the WHERE clause below returns over 1000 records:

WHERE (((Example.Example) Like "*" & [pSearch] & "*"));

While this returns 0 records:

WHERE (((Example.Example) Like "%" & [pSearch] & "%"));

Both of these WHERE clasues return 0 records to my ASP page.

So how do I use "%" in my situation?


"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:uY**************@TK2MSFTNGP03.phx.gbl...
Dave wrote:
>This is my query named "spVOC_Sp_Example_search" in Access 2003:

PARAMETERS [pSearch] Text ( 255 );
SELECT Example.Example
FROM Example
WHERE (((Example.Example) Like "*" & [pSearch] & "*"));
>How do I properly call an Access parameterized wildcard query from
ASP?

In order to call the query via ADO, you must change the Jet wildcards to
ODBc wildcards:

WHERE (((Example.Example) Like "%" & [pSearch] & "%"));

Then you can simply call it by:

set rs=createobject("adodb.recordset")
cn.spVOC_Sp_Example_search "a", rs

See:
http://www.google.com/groups?hl=en&l...TNGP12.phx.gbl

http://groups.google.com/groups?hl=e...tngp13.phx.gbl
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Mar 25 '07 #3
Dave wrote:
Thanks Bob

I think there is something fundamental I'm missing here.

I am not using dynamic SQL,
I know you're not.
my query resides on Access so in the
Access application the WHERE clause below returns over 1000 records:
Yes I know. Access uses DAO to execute your stored queries, so the Jet
wildcards can be used. When executing queries, even saved queries, via ADO,
the ODBC wildcards must be used. It's very nonintuitive, I know.
>
WHERE (((Example.Example) Like "*" & [pSearch] & "*"));

While this returns 0 records:

WHERE (((Example.Example) Like "%" & [pSearch] & "%"));

Both of these WHERE clasues return 0 records to my ASP page.
The latter should work. I've just tested it with this sample data:

abcd
efgh
halp
pqrs

I created a saved query called "wildcardsearch" with this sql:
SELECT Example
FROM Example
WHERE Example Like "%" & [psearch] & "%";

Using this code to execute the saved query:
<%
dim cn, rs, s
s="a"
set cn=createobject("adodb.connection")
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & server.MapPath("db7.mdb")
set rs=createobject("adodb.recordset")
cn.wildcardsearch s,rs
if not rs.EOF then
Response.Write rs.GetString(,,,"<BR>")
else
Response.Write "No records retrieved"
end if
rs.Close
cn.Close
%>

I get this result:
abcd
halp

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Mar 25 '07 #4
My sincere apologies.

It works fine now. I was testing improperly for the recordset.

Thank you for the example and your patience
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Dave wrote:
>Thanks Bob

I think there is something fundamental I'm missing here.

I am not using dynamic SQL,

I know you're not.
> my query resides on Access so in the
Access application the WHERE clause below returns over 1000 records:

Yes I know. Access uses DAO to execute your stored queries, so the Jet
wildcards can be used. When executing queries, even saved queries, via
ADO, the ODBC wildcards must be used. It's very nonintuitive, I know.
>>
WHERE (((Example.Example) Like "*" & [pSearch] & "*"));

While this returns 0 records:

WHERE (((Example.Example) Like "%" & [pSearch] & "%"));

Both of these WHERE clasues return 0 records to my ASP page.

The latter should work. I've just tested it with this sample data:

abcd
efgh
halp
pqrs

I created a saved query called "wildcardsearch" with this sql:
SELECT Example
FROM Example
WHERE Example Like "%" & [psearch] & "%";

Using this code to execute the saved query:
<%
dim cn, rs, s
s="a"
set cn=createobject("adodb.connection")
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & server.MapPath("db7.mdb")
set rs=createobject("adodb.recordset")
cn.wildcardsearch s,rs
if not rs.EOF then
Response.Write rs.GetString(,,,"<BR>")
else
Response.Write "No records retrieved"
end if
rs.Close
cn.Close
%>

I get this result:
abcd
halp

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Mar 25 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
1
by: deko | last post by:
I have a form where users can enter a string with asterisks to perform a wildcard search. Currently, the string entered by the user looks like this: *somestring* The purpose is to match any...
3
by: george.lengel | last post by:
Hello experts, I have been struggling for days to solve this problem and every suggestion I find via Google does not work for me. There is probably a solution out there that will do what I want,...
2
by: googlegroups.dsbl | last post by:
I'm really confused here, and am wondering if someone knows what could be the issue with my TableAdapter query. A few months ago, I created a really neat program that has th ability to search by...
9
by: romanko | last post by:
I'm running Access 2000 on Windows XP. I have a simple select query, with two tables joined at the "Account" field. The account field has 5 characters of text in both tables Table A is a...
4
MMcCarthy
by: MMcCarthy | last post by:
To view Access queries in SQL rather than Access query design - open the query design window and change the view to SQL: Select Statement SELECT FROM ; Append Statement INSERT INTO (, , )...
0
by: Gordon.E.Anderson | last post by:
short description: i've got a .net web site set up using a tableadapter attached to a sql server table - returning results only, no update of data. i've got a query (qry code below) set up to...
4
by: Cron | last post by:
Hi can someone give me a hand with this please? I'm trying to build a search filter that scans through a list of client names in a database as you type into a text box and filters the form records...
0
by: savage678 | last post by:
Hi Everyone, I am new to this forum and am i dire need of some help. I am trying to use wildcard searches in infopath. I have it connected to an access database using data connection. I have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.