Solved

Pattern matching question in SYBASE.

Posted on 2006-06-30
5
1,171 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
5 Comments
 
LVL 2

Accepted Solution

by:
TadHawkins earned 250 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
We have come a long way with backup and data protection — from backing up to floppies, external drives, CDs, Blu-ray, flash drives, SSD drives, and now to the cloud.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now