dbTalk Databases Forums  

SQL statement with quotation marks

comp.databases.ms-access comp.databases.ms-access


Discuss SQL statement with quotation marks in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Paradigm
 
Posts: n/a

Default SQL statement with quotation marks - 01-06-2005 , 11:40 AM






I am trying to create a recordset where some text fields are matching. The
problem is that some of the text fields contain quotation marks. I have
tried to create the sql string using replace eg.
"SELECT * FROM MYTABLE WHERE REPLACE(MYFIELD,"""",".") = """ &
REPLACE(MYTEXT,"""",".") & """"
but this does not work. Trying to replace the quotation marks with some
other character in this case the stop
How can I embed the quotation marks in the sql string?

Alex



Reply With Quote
  #2  
Old   
jv
 
Posts: n/a

Default Re: SQL statement with quotation marks - 01-06-2005 , 12:07 PM






Alex,

I also use the replace() function to eliminate quotations and
apostrophes for SQL statement and it works great for me (I actually
replace it double apostrophes, which becomes a single apostrophe).

Why is the WHERE clause REPLACE(MYFIELD,"""",".")= """ ?

Trying putting a breakpoint in VBA and then evaluate that SQL string in
the Immediate window.

Good Luck


Reply With Quote
  #3  
Old   
Paradigm
 
Posts: n/a

Default Re: SQL statement with quotation marks - 01-06-2005 , 12:35 PM



My staement is
STRSQL = "SELECT * FROM TBLINMAIL WHERE replace(Subject,"""",".") = """ &
Replace(mySubject, """", ".") & """"

but it shows in red as incorrect
"jv" <julie_vazquez (AT) hotmail (DOT) com> wrote

Quote:
Alex,

I also use the replace() function to eliminate quotations and
apostrophes for SQL statement and it works great for me (I actually
replace it double apostrophes, which becomes a single apostrophe).

Why is the WHERE clause REPLACE(MYFIELD,"""",".")= """ ?

Trying putting a breakpoint in VBA and then evaluate that SQL string in
the Immediate window.

Good Luck




Reply With Quote
  #4  
Old   
julie vazquez
 
Posts: n/a

Default Re: SQL statement with quotation marks - 01-06-2005 , 01:00 PM



Try this:

STRSQL = "SELECT * FROM TBLINMAIL WHERE Subject = '" &
Replace(mySubject, """", ".") & "'"

I don't think you need to put replace() around the field name part of
the expression, only around the value part.

Good Luck.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Reply With Quote
  #5  
Old   
Paradigm
 
Posts: n/a

Default Re: SQL statement with quotation marks - 01-06-2005 , 03:58 PM



Yes that works BUT I also need to replace the subject in the string with a
replace
eg.
STRSQL = "SELECT * FROM TBLINMAIL WHERE REPLACE(SUBJECT,"""",".") = " ETC
and it seems that I cannot use the replace in a query
Alex

"julie vazquez" <julie_vazquez (AT) hotmail (DOT) com> wrote

Quote:
Try this:

STRSQL = "SELECT * FROM TBLINMAIL WHERE Subject = '" &
Replace(mySubject, """", ".") & "'"

I don't think you need to put replace() around the field name part of
the expression, only around the value part.

Good Luck.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Reply With Quote
  #6  
Old   
julie vazquez
 
Posts: n/a

Default Re: SQL statement with quotation marks - 01-06-2005 , 06:15 PM



I don't see why you need to put a replace around your table field name.
It doesn't make sense.

But if you wish, you can put it like this:

strSQL = "SELECT * FROM TBLINMAIL WHERE replace(Subject,'""','.') = '" &
Replace(mySubject, """", ".") & "'"






*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Reply With Quote
  #7  
Old   
Ed Marzan
 
Posts: n/a

Default Re: SQL statement with quotation marks - 01-07-2005 , 02:43 PM



Do a google search for quotes in strings. Also check The Access Web
which has an elegant solution using Const cQuote = """"

Goog luck!


julie vazquez wrote:
Quote:
I don't see why you need to put a replace around your table field
name.
It doesn't make sense.

But if you wish, you can put it like this:

strSQL = "SELECT * FROM TBLINMAIL WHERE replace(Subject,'""','.') =
'" &
Replace(mySubject, """", ".") & "'"






*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Reply With Quote
  #8  
Old   
Salad
 
Posts: n/a

Default Re: SQL statement with quotation marks - 01-07-2005 , 06:19 PM



Paradigm wrote:

Quote:
I am trying to create a recordset where some text fields are matching. The
problem is that some of the text fields contain quotation marks. I have
tried to create the sql string using replace eg.
"SELECT * FROM MYTABLE WHERE REPLACE(MYFIELD,"""",".") = """ &
REPLACE(MYTEXT,"""",".") & """"
but this does not work. Trying to replace the quotation marks with some
other character in this case the stop
How can I embed the quotation marks in the sql string?

Alex


Why are you needing that? And your logic of trying to replace quotes
with a period and comparing them to a quote doesn't make sense. Check
the following line....it's more to what you want.

"SELECT * FROM MYTABLE WHERE REPLACE(MYFIELD,"""""",""."") =
REPLACE(MYTEXT,"""""",""."")"


To verify the above, Go to the Debug/Immediate Window. Enter
v = "SELECT * FROM MYTABLE WHERE REPLACE(MYFIELD,"""""",""."") =
REPLACE(MYTEXT,"""""",""."")"

? v

this will echo back
SELECT * FROM MYTABLE WHERE REPLACE(MYFIELD,""",".") =
REPLACE(MYTEXT,""",".")



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.