Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Pattern matching question in SYBASE.

Posted on 2006-06-30
5
Medium Priority
?
1,197 Views
Last Modified: 2012-06-27
Can anyone help me with this one. This should be straight forward but I cannot seem to get a good answer nmyself. I have a column in a table that is char(20) and is comprised of numeric values (99%) with a few non numeric values. I wish to select only the numeric values which vary in length from 1 digit to 9 digits.
Does anyone know an easy way to do this ?
Thanks.
Matthew.
0
Comment
Question by:matthewvaughan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 2

Accepted Solution

by:
TadHawkins earned 1000 total points
ID: 17019943
create table #N (N char(20))

insert #N select "123"
insert #N select "1d3"
insert #N select "xyz"

select *
from   #N
where  N like "%[a-zA-Z]%"

If you have other characters like !@#$%^&*() you can include those within the brackets as well ( just make sure that the first character inside the brackets is not the ^ as that has a special meaning in that position).

0
 
LVL 10

Expert Comment

by:bret
ID: 17021064
Won't that get rows that contain an alphabetic character, rather than rows that
are valid numerics?

Also doesn't work well for values such as

-123.456  (a valid number)
-123.4.56 (not a valid number)

27e5  ( a valid number)
2e7e5 ( not a valid number)

But if the problem is just positive integers, I would try something similar to
that - perhaps

select * from #n where patindex("%[^1234567890]%", N) = 0
go



An "isnumeric()" built-in function is coming in the ASE 15.0.1 release (around August/September 2006).
0
 
LVL 14

Expert Comment

by:Jan Franek
ID: 17031151
one not very elegant approach: try to convert it to numeric type - if it fails, it wan not numeric :-)
but you have to use cursor to make it work and try row by row, so if your table is big, it will probably take a long time
0
 
LVL 6

Expert Comment

by:ChrisKing
ID: 17036795
WHERE columnname NOT LIKE '%[^0-9]%'   -- integers

WHERE columnname NOT LIKE '%[^0-9.]%'   -- and decimal values too
0
 
LVL 6

Expert Comment

by:ChrisKing
ID: 17042846
hmmm - accepted the only answer that does not work
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you an Exchange administrator employed with an organization? And, have you encountered a corrupt Exchange database due to which you are not able to open its EDB file. This article will explain all the steps to repair corrupt Exchange database.
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question