dbTalk Databases Forums  

ASA 9.0.1: use of % sign in text or varchar column data and how tosearch for % sign

sybase.public.sqlanywhere.general sybase.public.sqlanywhere.general


Discuss ASA 9.0.1: use of % sign in text or varchar column data and how tosearch for % sign in the sybase.public.sqlanywhere.general forum.



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

Default ASA 9.0.1: use of % sign in text or varchar column data and how tosearch for % sign - 10-09-2009 , 12:56 PM






Hi,

Is it permissible for the "%" to be entered into data that is stored
in columns defined as text or varchar? For example, can the data
being stored in a text or varchar column be "Mr. Smith has a 50%
interest in the property"? Along the same line of thought, if
someone wants to search that text or varchar column for the "%" how do
you specify it in the SQL? Select * from <table> where <column> like
'%' doesn't work. I've tried '%%' and a lot of other things but I
can't make it work.

Thanks in advance for your help!
Sarah B. Anderson

Reply With Quote
  #2  
Old   
Breck Carter [TeamSybase]
 
Posts: n/a

Default Re: ASA 9.0.1: use of % sign in text or varchar column data and how to search for % sign - 10-09-2009 , 01:14 PM






Select * from <table> where <column> like '%a\%b%' ESCAPE '\';

....that will match a string containing a%b

Breck

On Fri, 9 Oct 2009 10:56:07 -0700 (PDT), Sarah <sanderson (AT) tnc (DOT) org>
wrote:

Quote:
Hi,

Is it permissible for the "%" to be entered into data that is stored
in columns defined as text or varchar? For example, can the data
being stored in a text or varchar column be "Mr. Smith has a 50%
interest in the property"? Along the same line of thought, if
someone wants to search that text or varchar column for the "%" how do
you specify it in the SQL? Select * from <table> where <column> like
'%' doesn't work. I've tried '%%' and a lot of other things but I
can't make it work.

Thanks in advance for your help!
Sarah B. Anderson
--
Breck Carter http://sqlanywhere.blogspot.com/

RisingRoad SQL Anywhere and MobiLink Professional Services
breck.carter (AT) risingroad (DOT) com

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

Default Re: ASA 9.0.1: use of % sign in text or varchar column data and howto search for % sign - 10-09-2009 , 01:20 PM



On Oct 9, 2:14*pm, "Breck Carter [TeamSybase]"
<NOSPAM__breck.car... (AT) gmail (DOT) com> wrote:
Quote:
Select * from <table> where <column> like '%a\%b%' ESCAPE '\';

...that will match a string containing a%b

Breck


Thanks Breck. Is there a way to search for a % sign on its own? In
other words, I want to find all rows where <column> contains a "%".

Also, is it ok to have the "%" in data in columns that are defined as
text or varchar? Thanks again for your help.

Sarah B. Anderson

Reply With Quote
  #4  
Old   
Breck Carter [TeamSybase]
 
Posts: n/a

Default Re: ASA 9.0.1: use of % sign in text or varchar column data and how to search for % sign - 10-10-2009 , 09:54 AM



This should work: LIKE '%\%%' ESCAPE '\'

The first and last % work like wild cards to match zero or more of any
characters, and the middle \% exactly matches a single % character.

Breck

On Fri, 9 Oct 2009 11:20:06 -0700 (PDT), Sarah <sanderson (AT) tnc (DOT) org>
wrote:

Quote:
On Oct 9, 2:14*pm, "Breck Carter [TeamSybase]"
NOSPAM__breck.car... (AT) gmail (DOT) com> wrote:
Select * from <table> where <column> like '%a\%b%' ESCAPE '\';

...that will match a string containing a%b

Breck



Thanks Breck. Is there a way to search for a % sign on its own? In
other words, I want to find all rows where <column> contains a "%".

Also, is it ok to have the "%" in data in columns that are defined as
text or varchar? Thanks again for your help.

Sarah B. Anderson
--
Breck Carter http://sqlanywhere.blogspot.com/

RisingRoad SQL Anywhere and MobiLink Professional Services
breck.carter (AT) risingroad (DOT) com

Reply With Quote
  #5  
Old   
Volker Barth
 
Posts: n/a

Default Re: ASA 9.0.1: use of % sign in text or varchar column data and howto search for % sign - 10-12-2009 , 02:55 AM



Sarah wrote:
Quote:
Also, is it ok to have the "%" in data in columns that are defined as
text or varchar? Thanks again for your help.

Sarah B. Anderson
It is ok to store *any* kind of chars in text/char columns - that's what
they are for. Your issue has just to do with LIKE search clauses, and
you're right that looking for chars that are used as wildcards is a
little bit more difficult. However, the solution is not to prevent the
storage of such data but to apply the correct escape sequences like
Breck has shown.

HTH
Volker

Reply With Quote
  #6  
Old   
Sarah
 
Posts: n/a

Default Re: ASA 9.0.1: use of % sign in text or varchar column data and howto search for % sign - 10-26-2009 , 11:02 AM



Quote:
This should work: LIKE '%\%%' ESCAPE '\'

The first and last % work like wild cards to match zero or more of any
characters, and the middle \% exactly matches a single % character.

Breck

Thanks Breck, that's exactly what I was looking for. I appreciate
your help!

Sarah Anderson

Reply With Quote
  #7  
Old   
Sarah
 
Posts: n/a

Default Re: ASA 9.0.1: use of % sign in text or varchar column data and howto search for % sign - 10-26-2009 , 11:05 AM



On Oct 12, 3:55*am, Volker Barth <No_VBarth (AT) Spam_GLOBAL-FINANZ (DOT) de>
wrote:
Quote:
Sarah wrote:

Also, is it ok to have the "%" in data in columns that are defined as
text or varchar? *Thanks again for your help.

Sarah B. Anderson

It is ok to store *any* kind of chars in text/char columns - that's what
they are for. Your issue has just to do with LIKE search clauses, and
you're right that looking for chars that are used as wildcards is a
little bit more difficult. However, the solution is not to prevent the
storage of such data but to apply the correct escape sequences like
Breck has shown.

HTH
Volker
Thanks, Volker. I appreciate confirmation that "%" signs are ok in
those columns. It turns out that the "problem" with % signs was due
to another part of our application, not SQL Anywhere. I didn't think
it was SQL Anywhere but was just trying to eliminate all the
possibilities. Thanks again for your response.

Sarah Anderson

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.