Home All Groups Group Topic Archive Search About

String RICHARD O'BRIAN in WHERE Clause

Author
25 Aug 2005 1:57 PM
MS News
Hi

I'm sure this is probably an elementary question, but I'm finding it
difficult to search for a name with an apostrophe in it, for example the
name in the Subject Header : O'Connel/O'Brian/O'Reily etc....

I have tried the obvious WHERE fname = 'O'Brian'

but that does not work, since it encapsulates the O as a string on its own?
Double quotes do not seem to work either?

Any suggestions?

Kind Regards

Ricky

Author
25 Aug 2005 1:59 PM
JP
How about

WHERE fname = 'O''Brian'

Cheers,
JP (Just a programmer;))


Show quote
"MS News" <m**@mis.com> wrote in message
news:uF2RIzXqFHA.3064@TK2MSFTNGP15.phx.gbl...
> Hi
>
> I'm sure this is probably an elementary question, but I'm finding it
> difficult to search for a name with an apostrophe in it, for example the
> name in the Subject Header : O'Connel/O'Brian/O'Reily etc....
>
> I have tried the obvious WHERE fname = 'O'Brian'
>
> but that does not work, since it encapsulates the O as a string on its
> own?
> Double quotes do not seem to work either?
>
> Any suggestions?
>
> Kind Regards
>
> Ricky
>
>
Author
25 Aug 2005 1:59 PM
Aaron Bertrand [SQL Server MVP]
> I have tried the obvious WHERE fname = 'O'Brian'

Did you try doubling up the apostrophe?

WHERE fname = 'O''Brian'
Author
25 Aug 2005 2:35 PM
MS News
Thanks JP & Aaron.

The Double Apostrophe worked just fine.

I don't suppose you guys would know how to make this dynamic.  Since I have
a table full of 1000+ names, which I use in the another query.  Is it
possible to checkt the name and see if there is an apostrophe and then add
another?

Kind Regards

Ricky


Show quote
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in message
news:eq04h0XqFHA.3404@TK2MSFTNGP11.phx.gbl...
> > I have tried the obvious WHERE fname = 'O'Brian'
>
> Did you try doubling up the apostrophe?
>
> WHERE fname = 'O''Brian'
>
>
Author
25 Aug 2005 2:42 PM
Aaron Bertrand [SQL Server MVP]
> I don't suppose you guys would know how to make this dynamic.  Since I
> have
> a table full of 1000+ names, which I use in the another query.  Is it
> possible to checkt the name and see if there is an apostrophe and then add
> another?

I don't quite understand what you think that will accomplish.  Are you
saying you want to update the table and save an extra apostrophe in all the
data values?

This is absolutely the wrong approach.  The second apostrophe acts as an
escape mechanism.  When you search for 'O''Brian' you will find the value
O'Brian (one apostrophe).  The doubling up belongs in the string passed to
the query, not in the data!
Author
25 Aug 2005 2:48 PM
Aaron Bertrand [SQL Server MVP]
> I don't suppose you guys would know how to make this dynamic.  Since I
> have
> a table full of 1000+ names, which I use in the another query.

Have you considered using a JOIN... then you don't have to worry about
pulling the name out and stuffing it back in, which is where the delimiter
problem comes in.

Show us what your tables look like, the data that is in them, and the query
you are trying to run...
http://www.aspfaq.com/5006

A
Author
25 Aug 2005 3:47 PM
JP
With out going into why you want to do that ... :)

How about

select replace(fname,'''','''''') from xYZ

--
Cheers,
JP (Just a programmer;)
------------------------------------------------------------------
A program is a device used to convert,
data into error messages
------------------------------------------------------------------
Show quote
"MS News" <m**@mis.com> wrote in message
news:%23$HXiIYqFHA.2432@TK2MSFTNGP10.phx.gbl...
> Thanks JP & Aaron.
>
> The Double Apostrophe worked just fine.
>
> I don't suppose you guys would know how to make this dynamic.  Since I
> have
> a table full of 1000+ names, which I use in the another query.  Is it
> possible to checkt the name and see if there is an apostrophe and then add
> another?
>
> Kind Regards
>
> Ricky
>
>
> "Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in
> message
> news:eq04h0XqFHA.3404@TK2MSFTNGP11.phx.gbl...
>> > I have tried the obvious WHERE fname = 'O'Brian'
>>
>> Did you try doubling up the apostrophe?
>>
>> WHERE fname = 'O''Brian'
>>
>>
>
>

AddThis Social Bookmark Button