Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Pattern matching question in SYBASE.

Posted on 2006-06-30
5
Medium Priority
?
1,203 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 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

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

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

971 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