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

how to deal with quotes and this sql statement

Here is the sql statement.

Set rs2 = db.OpenRecordset("select * from Names where InStr(descriptions" +
"+" + """" + "|" + """" + "," + """" + asearchkey + """" + ") > 0")
this searches a recorset and returns all the names that have asearchkey
somewhere in their description

so if "hello" is in "this is a hello test" will be returned
but this fails - "the item is 3" tall" fails becaus of the quote

How can I successfully search this field when their are quotes but leave the
database as is so I dont have to get rid of the quotes before I do the query
I dont want to do that.

what about the ' character too, I didnt test that.

Thanks


Nov 12 '05 #1
3 2369
Danny wrote:
Here is the sql statement.

Set rs2 = db.OpenRecordset("select * from Names where InStr(descriptions" +
"+" + """" + "|" + """" + "," + """" + asearchkey + """" + ") > 0")
this searches a recorset and returns all the names that have asearchkey
somewhere in their description

so if "hello" is in "this is a hello test" will be returned
but this fails - "the item is 3" tall" fails becaus of the quote

How can I successfully search this field when their are quotes but leave the
database as is so I dont have to get rid of the quotes before I do the query
I dont want to do that.

what about the ' character too, I didnt test that.

Thanks

Have you considered the LIKE operator
Where Description Like "*" & aSearchKey & "*"
or
Where Description Like '*' & aSearchKey & '*'

Nov 12 '05 #2

"Salad" <oi*@vinegar.com> wrote in message
news:j3******************@newsread1.news.pas.earth link.net...
Danny wrote:
Here is the sql statement.

Set rs2 = db.OpenRecordset("select * from Names where InStr(descriptions" + "+" + """" + "|" + """" + "," + """" + asearchkey + """" + ") > 0")
this searches a recorset and returns all the names that have asearchkey
somewhere in their description

so if "hello" is in "this is a hello test" will be returned
but this fails - "the item is 3" tall" fails becaus of the quote

How can I successfully search this field when their are quotes but leave the database as is so I dont have to get rid of the quotes before I do the query I dont want to do that.

what about the ' character too, I didnt test that.

Thanks

Have you considered the LIKE operator
Where Description Like "*" & aSearchKey & "*"
or
Where Description Like '*' & aSearchKey & '*'


Thanks,

I tried tihs and it seems to produce the same results without errors so it
does work, thank you
But this command is soo much slower than the instr command. I am dealing
with thousands of records and hte speed makes a difference.

Do you have any other suggestions?
How could I speed sometihng like this up?
Is there a way I can modify how I use the instr search command
Thanks in advance
Nov 12 '05 #3
Danny wrote:
"Salad" <oi*@vinegar.com> wrote in message
news:j3******************@newsread1.news.pas.earth link.net...
Danny wrote:
Here is the sql statement.

Set rs2 = db.OpenRecordset("select * from Names where
InStr(descriptions" +
"+" + """" + "|" + """" + "," + """" + asearchkey + """" + ") > 0")
this searches a recorset and returns all the names that have asearchkey
somewhere in their description

so if "hello" is in "this is a hello test" will be returned
but this fails - "the item is 3" tall" fails becaus of the quote

How can I successfully search this field when their are quotes but leave
the
database as is so I dont have to get rid of the quotes before I do the
query
I dont want to do that.

what about the ' character too, I didnt test that.

Thanks


Have you considered the LIKE operator
Where Description Like "*" & aSearchKey & "*"
or
Where Description Like '*' & aSearchKey & '*'

Thanks,

I tried tihs and it seems to produce the same results without errors so it
does work, thank you
But this command is soo much slower than the instr command. I am dealing
with thousands of records and hte speed makes a difference.

Do you have any other suggestions?
How could I speed sometihng like this up?
Is there a way I can modify how I use the instr search command
Thanks in advance


Your line with all the plusses and bars and quotes was simply too hard
to comprehend for my limited time.

I usually do something like
Dim strSQL As STring
strSQL = "Select * From Names Where " & _
"Instr(Description,asearchkey) > 0"
Set rs2 = db.OpenRecordset(strSQL,dbopensnapshot)

Nov 12 '05 #4

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

Similar topics

1
by: billmiami2 | last post by:
I'm trying to pass through a SQL statement to an Oracle database using OPENROWSET. My problem is that I'm not sure of the exact syntax I need to use when the SQL statement itself contains single...
3
by: J. Franchino | last post by:
Why doesn't this work? specifically, the space in "word word" throws it all off. What's the right way to do this? Thanks. -jf <script language="JavaScript"> function change_text(id,str) {...
5
by: Joel | last post by:
Hi, I incorporated a function in my code that whenever I use a string variable in an sql statement if the string contains a single quote it will encase it in double quotes else single quotes. ...
3
by: Danny | last post by:
Here is the sql statement. Set rs2 = db.OpenRecordset("select * from Names where InStr(descriptions" + "+" + """" + "|" + """" + "," + """" + asearchkey + """" + ") > 0") this searches a...
3
by: Stefania Scott | last post by:
How do I resolve the problem of passing a string that has quotes within in a SQL statement? Sometimes the string contains a single quote (') and some others it contains the double quote (")? Any...
2
by: Wayne | last post by:
This is probably simple but: The following portion of an SQL statement that I've copied from the SQL view of the query grid (the query works fine) is giving me an error to the effect that it is...
24
by: deko | last post by:
I'm trying to log error messages and sometimes (no telling when or where) the message contains a string with double quotes. Is there a way get the query to insert the string with the double...
2
by: barry.edmund.wright | last post by:
Hi All, I want to build a Find Statement on the fly. The code below starting with 'This Code Works! is fine but as I said I want to build the Me!cboSelect1 & "=" & rs(Me!cboSelect1) portion of...
1
by: swep | last post by:
To any who might be able to help this is the situation.I have a dropdown list that gets populated from SQL. It contains both single and double quotes. It populates the dropdown list just fine. I...
2
by: ncsthbell | last post by:
I am trying to construct a 'Copy' statement in Access 2000 vb that I will actually write out to create a .bat file. My problem is that I need to put quotes around the vcFileFrom and vcFileTo...
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: 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:
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.