Solved

Pattern matching question in SYBASE.

Posted on 2006-06-30
5
1,188 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Copy a TadoDataSet to another and apply changes to database. 11 1,306
Sybase Customized sp_thresholdaction 2 711
SQL Syntax 6 404
ODBC error on 64bit mahcine 4 116
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

710 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