473,624 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Returning Records with Apostrophes in text strings using code

I've tried various combinations of quotation marks and asterisks but I can't
see to get the syntax right. Could someone post a working example?

Many thanks.
Keith.
Nov 13 '05 #1
5 3071
"Keith" <ke*********@ba eAWAYWITHITsyst ems.com> wrote in message
news:42******** **@glkas0286.gr eenlnk.net...
I've tried various combinations of quotation marks and asterisks but I
can't see to get the syntax right. Could someone post a working example?

Many thanks.
Keith.

The apostrophes don't normally cause a problem because the string is wrapped
in double quotes, eg

SELECT * FROM tblAlbum WHERE tblAlbum.TrackL ist LIKE "*Joe's Garage*"

Things would only go wrong when you looked for Pete "The Punk" Smith where
you would have to double up the speech marks. You could try pasting this
into a new module, which would let you simply have:

strSQL = "SELECT * FROM tblAlbum WHERE
tblAlbum.TrackL ist=AddQuotes(s trCriterion,Dou bleQuote)

or
strCriterion = "*" & strCriterion & "*"
strSQL = "SELECT * FROM tblAlbum WHERE tblAlbum.TrackL ist LIKE
AddQuotes(strCr iterion,DoubleQ uote)

Option Compare Database
Option Explicit

Public Enum QuoteType
NoQuote
SingleQuote
DoubleQuote
End Enum
Public Function AddQuotes(strVa lue, Q As QuoteType) As String

Dim strReturn As String

Select Case Q

Case QuoteType.Singl eQuote
strReturn = Replace(strValu e, "'", "''")
strReturn = "'" & strReturn & "'"

Case QuoteType.Doubl eQuote
strReturn = Replace(strValu e, """", """""")
strReturn = """" & strReturn & """"

Case Else
strReturn = strValue

End Select

AddQuotes = strReturn

End Function


Nov 13 '05 #2
"Justin Hoffman" <j@b.com> wrote in message
news:d7******** **@nwrdmz01.dmz .ncs.ea.ibs-infra.bt.com...
"Keith" <ke*********@ba eAWAYWITHITsyst ems.com> wrote in message
news:42******** **@glkas0286.gr eenlnk.net...
I've tried various combinations of quotation marks and asterisks but I
can't see to get the syntax right. Could someone post a working example?

Many thanks.
Keith.

The apostrophes don't normally cause a problem because the string is
wrapped in double quotes, eg

SELECT * FROM tblAlbum WHERE tblAlbum.TrackL ist LIKE "*Joe's Garage*"

Thanks for your response Justin. What I'm trying to return is

WHERE MyField LIKE "* ' *"

in other words any record with an apostrophe in it (so that I can remove
it). I don't seem to be able to get it to work.

Regards,
Keith.
Nov 13 '05 #3
"Keith" <ke*********@ba eAWAYWITHITsyst ems.com> wrote in message
news:42******** **@glkas0286.gr eenlnk.net...
"Justin Hoffman" <j@b.com> wrote in message
news:d7******** **@nwrdmz01.dmz .ncs.ea.ibs-infra.bt.com...
"Keith" <ke*********@ba eAWAYWITHITsyst ems.com> wrote in message
news:42******** **@glkas0286.gr eenlnk.net...
I've tried various combinations of quotation marks and asterisks but I
can't see to get the syntax right. Could someone post a working
example?

Many thanks.
Keith.

The apostrophes don't normally cause a problem because the string is
wrapped in double quotes, eg

SELECT * FROM tblAlbum WHERE tblAlbum.TrackL ist LIKE "*Joe's Garage*"

Thanks for your response Justin. What I'm trying to return is

WHERE MyField LIKE "* ' *"

in other words any record with an apostrophe in it (so that I can remove
it). I don't seem to be able to get it to work.

Regards,
Keith.


Aha - just enclose it in square brackets

Like "*[']*"

or use the Instr function:

....WHERE InStr(Nz([MyField]),Chr$(39))>0
Nov 13 '05 #4
"Justin Hoffman" <j@b.com> wrote in message
news:d7******** **@nwrdmz02.dmz .ncs.ea.ibs-infra.bt.com...

Thanks for your response Justin. What I'm trying to return is

WHERE MyField LIKE "* ' *"

in other words any record with an apostrophe in it (so that I can remove
it). I don't seem to be able to get it to work.

Regards,
Keith.


Aha - just enclose it in square brackets

Like "*[']*"

or use the Instr function:

...WHERE InStr(Nz([MyField]),Chr$(39))>0

I'd already tried the square brackets but it didn't work for me (I already
use that method for finding wildcard characters) but I will have a play with
the InStr function. Many thanks again.

Keith.
Nov 13 '05 #5
"Keith" <ke*********@ba eAWAYWITHITsyst ems.com> wrote in message
news:42******** **@glkas0286.gr eenlnk.net...
or use the Instr function:

...WHERE InStr(Nz([MyField]),Chr$(39))>0
I'd already tried the square brackets but it didn't work for me (I already
use that method for finding wildcard characters) but I will have a play
with the InStr function. Many thanks again.


That has worked splendidly Justin, many thanks for your help.
Nov 13 '05 #6

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

Similar topics

2
3100
by: Poster | last post by:
After creating an IN clause from a bunch of character strings created by a Word macro, Query Analyzer complains about a syntax error. The macro takes a column full of character strings and wraps apostrophes (single-quotes) around each string and adds a comma to the end of each line, ready to paste into a Query Analyzer session. The problem is that Query Analyzer doesn't recognize the MS-Word apostrophes. It has nothing to do with the...
1
1573
by: Grant Davis | last post by:
We currently have an SQL db running on a web server. One of these fields is a large(ish) amount of text data – up to 400 characters – and has been cast variously as varchar, nchar and text type to overcome a problem. The problem appears to be in retrieving the data via ASP. I understand that ASP can handle string data of this size so I am okay there. When the records are retrieved from the db, the data string length =0. I know the data is...
3
9808
by: James Foreman | last post by:
I've got a set of emails in a table, where sometimes they've failed to input the @ properly. Eg james.foreman'abcmail.co.uk How do I write a replace to deal with that? Also, I've got a set of names in a table, all in lower case. I can easily capitalise the first letter of each name, but if it's somebody like O'Brien, I'd like to get that right too (so need to be able to
7
1604
by: sienaman | last post by:
I have a C# dll with a COM interface that is successfully call by a C++ client. One of the parameters is a string, the method looks like void Goofy(string strUserInput, out string strOutput); I make an assignment in the C# COM object to strOutput like strOutput = some system.string but the string is never returned to the C++ client, it always returns "". I tried setting strOutput to a stack value like strOutput = "Ge"; and the
4
1656
by: Nathan | last post by:
Hi, I'm doing a database app using MS Access and OleDb adapters, and I'm having trouble with getting strings containing apostrophes in and out of the database. I read through a thread below with subject "Apostrophys in text field - SQL Server as backend" and now I'm trying to figure out how to make it work in my case, particularly the input from William Ryan. What I have are a couple fields to be inserted directly as a new row, and...
3
3448
by: melnhed | last post by:
---Report the current filtered records from a Form--- Hello All, I've seen this topic discussed before, but the solution described then doesn't work in my particular case. My Config: Access 2002 front-end using SQL Server 2000 (MSDE actually) via ADP/ADE Access Data Project.
16
3037
by: radio1 | last post by:
---Report the current filtered records from a Form (in an ADP project)--- Hello All, I've seen this topic discussed before, but the solution described then doesn't work in my particular case. My Config: Access 2002 front-end using SQL Server 2000 (MSDE actually) via ADP/ADE Access Data Project. I have a form (containing about 80 fields) on which I allow the user to apply field/form filters -- this works fine.
9
7876
by: Paul | last post by:
Hi, I feel I'm going around circles on this one and would appreciate some other points of view. From a design / encapsulation point of view, what's the best practise for returning a private List<as a property. Consider the example below, the class "ListTest" contains a private "List<>" called "strings" - it also provides a public method to add to that list,
13
2107
by: jfarthing | last post by:
Hi everyone! I am using the script below to search a db. If the is more than one match in the db, all goes well. But if there is only one match in the db, nothing gets displayed. Any suggestions will be greatly appreciated. Jim #! /usr/bin/perl -w use strict;
0
8238
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8174
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8680
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7164
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2607
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1485
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.