473,394 Members | 1,703 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,394 software developers and data experts.

ASP LIKE query using parameterized query

In Access you use "*" + [passed variable] + "*", + can be replaced with &
Calling a parameterized query in Access requires % be used in place of *,
however, all that I have read show dynamic SQL passed to Access:

WHERE [some column] LIKE '" & ASPvar & "' % ORDER BY ...

However, my call is similar to:

conn.qMyLookup strVar, rs

If I modify the query in Access to:

"%" & [passed variable] & "%"

I get all records. If I only put it at the end, as suggested, I only get
matches at the end, not throughout the column.

Ex.

search for 'a'

Rows:

abc
bca
cab

all that is returned is 'bca' If I used the % before and after, it will
return all 3 rows in my recordset. I've done this before but I cannot
remember if I ever used performed a wildcard search with a parameterized
query. Am I restricted to using only dynamic SQL to get this to work?

Any help appreciated.

Roland Hall


Jan 12 '07 #1
8 8021
Roland Hall wrote:
In Access you use "*" + [passed variable] + "*", + can be replaced
with & Calling a parameterized query in Access requires % be used in
place of *, however, all that I have read show dynamic SQL passed to
Access:
WHERE [some column] LIKE '" & ASPvar & "' % ORDER BY ...

However, my call is similar to:

conn.qMyLookup strVar, rs

If I modify the query in Access to:

"%" & [passed variable] & "%"

I get all records. If I only put it at the end, as suggested,
I don't understand what you mean by this. Put what "at the end"?
I only
get matches at the end, not throughout the column.

Ex.

search for 'a'

Rows:

abc
bca
cab

all that is returned is 'bca'
So you used
... LIKE "%' & parm
in the query, right?
If I used the % before and after, it
will return all 3 rows in my recordset. I've done this before but I
cannot remember if I ever used performed a wildcard search with a
parameterized query. Am I restricted to using only dynamic SQL to
get this to work?
It's not clear to me what you want. Which row do you want returned and why?

--
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"
Jan 12 '07 #2
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:el**************@TK2MSFTNGP06.phx.gbl...
Roland Hall wrote:
>In Access you use "*" + [passed variable] + "*", + can be replaced
with & Calling a parameterized query in Access requires % be used in
place of *, however, all that I have read show dynamic SQL passed to
Access:
WHERE [some column] LIKE '" & ASPvar & "' % ORDER BY ...

However, my call is similar to:

conn.qMyLookup strVar, rs

If I modify the query in Access to:

"%" & [passed variable] & "%"

I get all records. If I only put it at the end, as suggested,

I don't understand what you mean by this. Put what "at the end"?
%
>I only
get matches at the end, not throughout the column.

Ex.

search for 'a'

Rows:

abc
bca
cab

all that is returned is 'bca'

So you used
... LIKE "%' & parm
in the query, right?
Actually to get my query value to return any row where my value is found, I
need it before and after (it = %)
> If I used the % before and after, it
will return all 3 rows in my recordset. I've done this before but I
cannot remember if I ever used performed a wildcard search with a
parameterized query. Am I restricted to using only dynamic SQL to
get this to work?
It's not clear to me what you want. Which row do you want returned and
why?
I found my errors, I had two. I had 3 nested IIFs in my query and decided
to make 3 different queries for two reasons:

1. Access is very limited compared to SQL
2. I couldn't get it to work

After that, I couldn't get the query which returns projects by name to work
but I was still passing the type of request, the client ID and the client
job number, all of which I no longer needed. I only needed to now pass the
project name.

I also had an error in my main app where I was passing the wrong ID in my
javascript to my remote scripting function.

Good to hear from you. Haven't talked to you in awhile and thanks for
responding.

This is the query I'm using that actually was not the part of the problem.

SELECT Projects.[Client ID], Projects.[Client Job Number], Projects.[Project
Name], Projects.[Project Number]
FROM Projects
WHERE [Project Name] LIKE "%" & [iprojectName] & "%"
ORDER BY [Project Name];

This is the nested IIF query I gave up on:

SELECT Projects.[Client ID], Projects.[Client Job Number], Projects.[Project
Name], Projects.[Project Number]
FROM Projects
WHERE (((IIf([itype]=2,[Project Name] LIKE "%" + [iprojectName] +
"%",IIf([itype]=0,[Client ID]=[iclientid],IIf([itype]=1,[Client Job
Number]=[iclientJobNumber]))))<>False))
ORDER BY IIf([itype]=2,[Project Name],IIf([itype]=0,[Client Job
Number],IIf([itype]=1,[Client ID])));

I have 3 text fields that allow only one entry type to be passed; client ID,
client job number or project name. This is a timesheet app for an
architectual firm.

My remote scripting script:

// getprojects.js
var x;
function getProjects(itype,v) {
var cid = '', cjn = '', pn = '', p = '';
switch(itype) {
case 0:
cid = v;
break;
case 1:
cjn = v;
break;
default:
pn = v;
break;
}
var url = "getprojects.asp?itype=" + itype + "&cid=" + cid + "&cjn=" + cjn
+ "&pn=" + pn;
try { x = new XMLHttpRequest(); }
catch (error) {
try { x = new ActiveXObject("MSXML2.XMLHTTP"); }
catch (error) { return false; }
}
x.open("GET", url, true);
x.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
x.onreadystatechange = function() {
if (x.readyState == 4 && x.status == 200) {
// alert(x.responseText);
document.getElementById('projects').innerHTML = x.responseText;
return true;
}
}
x.send(null);
return true;
}

My timesheet script that called the remote scripting:
prt "function cjncheck(id) {"
prt " switch(id) {"
prt " case 'cid':"
prt " document.getElementById('cjn').value='';"
prt " document.getElementById('pn').value='';"
prt " event.keyCode == 13 ?
getProjects(0,document.getElementById('cid').value ): null;"
prt " break;"
prt " case 'cjn':"
prt " document.getElementById('cid').value='';"
prt " document.getElementById('pn').value='';"
prt " event.keyCode == 13 ?
getProjects(1,document.getElementById('cjn').value ): null;"
prt " break;"
prt " case 'pn':"
prt " document.getElementById('cid').value='';"
prt " document.getElementById('cjn').value='';"
prt " event.keyCode == 13 ?
getProjects(2,document.getElementById('pn').value) : null;"
prt " }"
prt " }"
The last keyCode test was passing id cjn, instead of pn. I often copy my
code instead of rewriting similar lines and I missed changing the ID.

My little asp script that made the call to the query that was still passing
all variables, which were no longer needed once they were split into 3
different queries.

sub getProjects(itype, iclientid, iclientJobNumber, iprojectName)
dim projects, i
SQLrsConnect()
select case itype
case "0"
conn.qProjectClientID iclientid, rs
case "1"
conn.qProjectClientJobNumber iclientJobNumber, rs
case "2"
conn.qProjectName iprojectName, rs
case else
SQLrsDisconnect()
lprt "Error! itype is not 0, 1 or 2"
Response.End
end select
prt "<table>"
if not (rs.BOF or rs.EOF) then
projects = rs.GetRows()
lprt "records: " & ubound(projects,2)
SQLrsDisconnect()
for i = 0 to ubound(projects,2)
prt "<tr><td>" & right("00" & projects(0,i),3) & "-" & right("00" &
projects(1,i),3) & " " & projects(2,i) & "</td></tr>"
next
else
SQLrsDisconnect()
prt "<tr><td>no records returned</td></tr>"
end if
prt "</table>"
end sub
It's pretty simple code but I still lost hair on it. If the database wasn't
so big and complicated I'd move it to SQL before writing the app but I
didn't have time. It's one day overdue and I have a target on my back.

--

Roland Hall


Jan 12 '07 #3

"Roland Hall" <nobody@nowherewrote in message
news:u%****************@TK2MSFTNGP02.phx.gbl...
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:el**************@TK2MSFTNGP06.phx.gbl...
>Roland Hall wrote:
>>In Access you use "*" + [passed variable] + "*", + can be replaced
with & Calling a parameterized query in Access requires % be used in
place of *, however, all that I have read show dynamic SQL passed to
Access:
WHERE [some column] LIKE '" & ASPvar & "' % ORDER BY ...

However, my call is similar to:

conn.qMyLookup strVar, rs

If I modify the query in Access to:

"%" & [passed variable] & "%"

I get all records. If I only put it at the end, as suggested,

I don't understand what you mean by this. Put what "at the end"?

%
>>I only
get matches at the end, not throughout the column.

Ex.

search for 'a'

Rows:

abc
bca
cab

all that is returned is 'bca'

So you used
... LIKE "%' & parm
in the query, right?

Actually to get my query value to return any row where my value is found,
I need it before and after (it = %)
>> If I used the % before and after, it
will return all 3 rows in my recordset. I've done this before but I
cannot remember if I ever used performed a wildcard search with a
parameterized query. Am I restricted to using only dynamic SQL to
get this to work?
It's not clear to me what you want. Which row do you want returned and
why?

I found my errors, I had two.
[snip]

Does this mean you have resolved the issue?

--
Mike Brind
Jan 12 '07 #4
Roland Hall wrote:
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:el**************@TK2MSFTNGP06.phx.gbl...
>Roland Hall wrote:
>>In Access you use "*" + [passed variable] + "*", + can be replaced
with & Calling a parameterized query in Access requires % be used in
place of *, however, all that I have read show dynamic SQL passed to
Access:
WHERE [some column] LIKE '" & ASPvar & "' % ORDER BY ...

However, my call is similar to:

conn.qMyLookup strVar, rs

If I modify the query in Access to:

"%" & [passed variable] & "%"

I get all records.
You get ALL records? Even those that don't contain the passed value?
If I only put it at the end, as suggested,
>>
I don't understand what you mean by this. Put what "at the end"?

%
>>I only
get matches at the end, not throughout the column.

Ex.

search for 'a'

Rows:

abc
bca
cab

all that is returned is 'bca'

So you used
... LIKE "%' & parm
in the query, right?

Actually to get my query value to return any row where my value is
found, I need it before and after (it = %)
So put it there. I don't understand the problem.

<snip TMI>
--
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"
Jan 12 '07 #5
"Roland Hall" <nobody@nowherewrote in message
<eL*************@TK2MSFTNGP06.phx.gbl>:
In Access you use "*" + [passed variable] + "*", + can be replaced
with & Calling a parameterized query in Access requires % be used in
place of *, however, all that I have read show dynamic SQL passed to
Access:

WHERE [some column] LIKE '" & ASPvar & "' % ORDER BY ...

However, my call is similar to:

conn.qMyLookup strVar, rs

If I modify the query in Access to:

"%" & [passed variable] & "%"

I get all records. If I only put it at the end, as suggested, I only
get matches at the end, not throughout the column.

Ex.

search for 'a'

Rows:

abc
bca
cab

all that is returned is 'bca' If I used the % before and after, it
will return all 3 rows in my recordset. I've done this before but I
cannot remember if I ever used performed a wildcard search with a
parameterized query. Am I restricted to using only dynamic SQL to
get this to work?

Any help appreciated.

Roland Hall
You might try altering the stored Jet query to

....
WHERE [Project Name] LIKE [iprojectName]
....

Then pass the wildcards with the parameter. Dunno how that's done
with ASP (seeing this from ...access.queries), but I suppose it could
look something like this

conn.qMyLookup "%" + strVar + "%", rs

--
Roy-Vidar
Jan 12 '07 #6
"Mike Brind" <pa*******@hotmail.comwrote in message
news:uG**************@TK2MSFTNGP03.phx.gbl...
>
"Roland Hall" <nobody@nowherewrote in message
news:u%****************@TK2MSFTNGP02.phx.gbl...
>"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:el**************@TK2MSFTNGP06.phx.gbl...
>>Roland Hall wrote:
In Access you use "*" + [passed variable] + "*", + can be replaced
with & Calling a parameterized query in Access requires % be used in
place of *, however, all that I have read show dynamic SQL passed to
Access:
WHERE [some column] LIKE '" & ASPvar & "' % ORDER BY ...

However, my call is similar to:

conn.qMyLookup strVar, rs

If I modify the query in Access to:

"%" & [passed variable] & "%"

I get all records. If I only put it at the end, as suggested,

I don't understand what you mean by this. Put what "at the end"?

%
>>>I only
get matches at the end, not throughout the column.

Ex.

search for 'a'

Rows:

abc
bca
cab

all that is returned is 'bca'

So you used
... LIKE "%' & parm
in the query, right?

Actually to get my query value to return any row where my value is found,
I need it before and after (it = %)
>>> If I used the % before and after, it
will return all 3 rows in my recordset. I've done this before but I
cannot remember if I ever used performed a wildcard search with a
parameterized query. Am I restricted to using only dynamic SQL to
get this to work?
It's not clear to me what you want. Which row do you want returned and
why?

I found my errors, I had two.

[snip]

Does this mean you have resolved the issue?
Yes, that's why I listed the code to help others. My LIKE query was not the
issue after all.

--

Roland Hall
Jan 13 '07 #7

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:um**************@TK2MSFTNGP06.phx.gbl...
Roland Hall wrote:
>"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:el**************@TK2MSFTNGP06.phx.gbl...
>>Roland Hall wrote:
In Access you use "*" + [passed variable] + "*", + can be replaced
with & Calling a parameterized query in Access requires % be used in
place of *, however, all that I have read show dynamic SQL passed to
Access:
WHERE [some column] LIKE '" & ASPvar & "' % ORDER BY ...

However, my call is similar to:

conn.qMyLookup strVar, rs

If I modify the query in Access to:

"%" & [passed variable] & "%"

I get all records.

You get ALL records? Even those that don't contain the passed value?
Yes, but my 2nd response explains what the issues were and what it took to
fix it.

--

Roland Hall
Jan 13 '07 #8
"RoyVidar" <ro*************@yahoo.nowrote in message
news:mn***********************@yahoo.no...
"Roland Hall" <nobody@nowherewrote in message
<eL*************@TK2MSFTNGP06.phx.gbl>:
>In Access you use "*" + [passed variable] + "*", + can be replaced
with & Calling a parameterized query in Access requires % be used in
place of *, however, all that I have read show dynamic SQL passed to
Access:

WHERE [some column] LIKE '" & ASPvar & "' % ORDER BY ...

However, my call is similar to:

conn.qMyLookup strVar, rs

If I modify the query in Access to:

"%" & [passed variable] & "%"

I get all records. If I only put it at the end, as suggested, I only
get matches at the end, not throughout the column.

Ex.

search for 'a'

Rows:

abc
bca
cab

all that is returned is 'bca' If I used the % before and after, it
will return all 3 rows in my recordset. I've done this before but I
cannot remember if I ever used performed a wildcard search with a
parameterized query. Am I restricted to using only dynamic SQL to
get this to work?

Any help appreciated.

Roland Hall

You might try altering the stored Jet query to

...
WHERE [Project Name] LIKE [iprojectName]
...

Then pass the wildcards with the parameter. Dunno how that's done
with ASP (seeing this from ...access.queries), but I suppose it could
look something like this

conn.qMyLookup "%" + strVar + "%", rs
I thought of that but still didn't work when I tried it. It may work that
way but my 2nd response shows the query was not the problem, at least after
I split it into 3 queries. I just needed to modify my calls and I had one
error in a javascript routine.

--

Roland Hall
Jan 13 '07 #9

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

Similar topics

3
by: PiGei | last post by:
Hi all, I'm trying to build a function that - providing the dbname and the query name - show the results. I don't know how to solve this problem... when I try to insert the variable into this...
8
by: deko | last post by:
I'm trying to open a Recordset based on a parameterized query. I'm kind of new to parameterized queries, so I'm sure I'm missing something simple. Set qdfs = db.QueryDefs Set qdf =...
1
by: Jorell | last post by:
Hey everyone, I am currently using Microsofts DataAccess Application block ( SQLHelper ) and what I want to do is use a parameterized query instead of just SQL. I can not use stored procedures,...
11
by: anony | last post by:
Hello, I can't figure out why my parameterized query from an ASP.NET page is dropping "special" characters such as accented quotes & apostrophes, the registered trademark symbol, etc. These...
2
by: Howard | last post by:
How do I do this with parameterized query? without parameterized query: string search = "hello world search"; search = search.Replace(" ", " AND "); SELECT * FROM TABLE1 WHERE TEXT LIKE '%' +...
2
by: JSheble | last post by:
After building a parameterized ADO query, is there a method or a statement where you could see the actual query, with the parameterized values included?? -- Using Opera's revolutionary e-mail...
29
by: wizofaus | last post by:
I previously posted about a problem where it seemed that changing the case of the word "BY" in a SELECT query was causing it to run much much faster. Now I've hit the same thing again, where...
11
by: funky | last post by:
hello, I've got a big problem ad i'm not able to resolve it. We have a server running oracle 10g version 10.1.0. We usually use access as front end and connect database tables for data extraction....
3
by: xlar54 | last post by:
Is there a way to see the exact SQL being generated from a parameterized query? I am using this technique but am getting some strange SQL errors during execution and I would like to see the final...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.