Sonny,
<Mufasa climbs on soapbox>
Your situation becomes complex because whoever designed your columns (e.g., "lot_nbr" and "rcvr" at the very least), allowed the columns to become
very undisciplined...to be completely candid, crappy data live in those columns:
1) "R" and "W" are acting as some sort of indicators and, as a result, should be in columns separate from "lot_nbr" (and possibly "rcvr").
2) And you said,
Sonny said:
...seems like its only records that doesnt have a number in the 2nd character, which i dont care about those records...i only care about the records where the second character is a number after a R or W , etc.
The fact that "anything goes" (seemingly) in your columns means that your columns are simply "garbage cans" full of data and you must sort throught the "muck" every time you want to process your data. The data in your columns should act in disciplined, predictable ways. You should not have to constantly use overly contrived WHERE statements to decide whether you should process a row in one of "umpty-twelve" different ways.
Often times, when I point out that data is badly misbehaving, people respond something like
Well, this is the way our data is...I can't do anything about it...I'm only a <xyz-position>...Somebody else screwed up long, long ago. Can't you just quickly tell me what to do to get past this problem so that I can get on with what I really want to be doing?
At some point, if one is going to stop working in a trash heap, they must take ownership of the problem and be a force for implementing a "clean-up" of the situation. You might not be able to implement the resolution all by yourself, but you can (and perhaps, must) declare that "The Emporer is wearing no clothing."
<Mufasa climbs off soapbox>
So, given that:
1) I do not have a copy of your data to be able to uncover all the possible "exceptions" to your data that will cause trouble with your queries, and
2) I don't know how much authority and ability you have to "fix" your data to behave properly, and
2) I do not know how much of all of this you understand versus "Mufasa, can't you please just give me code that will untangle me from my knickers"
...We run the risk of spending the rest of the day on this issue and still not resolving, to your satisfaction, your problem(s).
So, since, by now, you are probably rather angry with my assessment, I'll try now to prove that I
really want to help you:
Issue 1: "lot_nbr" and "rcvr" contain
bad information...trailing blank spaces. Those trailing blank spaces cause problems for all comparisons: character comparisons between character expressions containing trailing blank spaces become problematic and between numeric expressions become impossible (as you discovered earlier).
Therefore, whenever you want to deal with expressions containing trailing blank spaces, you must first use the TRIM() or RTRIM() functions to get rid of those trailing blanks.
Issue 2: If you want do deal with rows whose expressions contain only 'R' or 'W' in the first character and a numeric character in the second character, then you must constantly test for that condition with code such as:
Code:
...WHERE substr(<column>,1,1) in ('R','W')
AND '0123456789' like '%'||substr(<column>,2,1)||'%'
...
That is an annoying hassle, but that's the constant price you must pay for poorly designed/poorly constrained data...You must implement data discipline for such expressions via convoluted, more-complex-than-necessary WHERE clauses.
So, this side of cleaning up your data, I've "given you a (not-so-quick) run down on what you should do."
![[santa] [santa] [santa]](/data/assets/smilies/santa.gif)
Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services:
www.dasages.com]