Solved

Pattern matching question in SYBASE.

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

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
Debugging PowerBuilder Nested Report / Datawindow Parameters 4 882
Sybase - sp_cacheconfig 1 1,025
performance measure of  running SSIS package 4 227
SQL Query Help! 11 130
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

763 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