Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove Range of Numbers from a Text String

Status
Not open for further replies.

crystal123456

Programmer
Jan 24, 2011
20
0
0
US
Hello,

I have a field that I need to remove a certain range of numbers from, however, this field is VARCHAR2 and can contain letters.

My current code is as follows (in the Where clause): field.field_name not between '27000000' and '27999999'

The problem is this is also taking out records that are not in this range, such as 27000.

What code can I place in the where clause to solve this issue?

Thanks for the help!
 
I have a couple of comments about this.

1. There is no such thing as a varchar2 in sql server. I'm guessing that you are actually using Oracle (or another database type). As such, you are likely to get better advice on a forum that is specific to your database engine.

2. If you want to treat data as an integer, then it should be stored in an integer field. This will solve several problems for you. Specifically, you'll use less storage space, sorting will work the way you expect it to, and filters become ridiculously easy.

3. If you cannot change the data type of the column (been there, done that), then you could convert the data to an integer before doing the comparison. Something like this:

Convert(Int, field.field_name) not between 27000000 and 27999999



-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Hi gmmastros,

My apologies, I am in fact using Oracle SQL.

Letters still need to be in some of the records of the field, so it does need to remain a text field.

I will try the convert function that you advised.

Thanks
 
The convert function will fail unless you remove the letters first. I would suggest a post on the oracle forum will get someone who can help you with the PL\SQL for that.

Dan

----------------------------------------

Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind - Bernard Baruch

Computer Science is no more about computers than astronomy is about telescopes - EW Dijkstra
----------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top