Nick_N
01-08-2002, 02:55 AM
I've got an access database which has text fields containing (mostly) numbers e.g.
165
234x412
56x5
1000
and also some blank entries.
The problem is that I want to sort the query by these fields numerically so that:
1000 > 200
and 100x45 > 90x15
(string sort returns "200" > "1000" and "90x15" > "100x45", of course.)
I'm doing ORDER BY CInt(fieldname)
But it dies on any fields with the "x" in (i.e. not pure numeric):
'Data type mismatch in criteria expression'
Also, in any recordsets containing blank entries in the field I am sorting on, I get this error:
'Invalid use of Null'
CInt seems rather unforgiving. Are there alternatives I can use in SQL queries which will assign zero to a null text string, and fail gracefully when non-numeric characters are present?
Or can I add a custom conversion routine (how?)
e.g. IdealConversion("145x56") returns 145
Or is reworking the database (split nnnxmmm into two separate numeric fields, add zeros in all blank fields) the only way forward.
I notice DavidR said in another thread:
-------------------------------------------
Depending on your database design, it seems to me you'd be better off storing alpha, numeric, and date data in separate fields with appropriate data types. You're probably going to find it MUCH more usable in the future (I speak from the voice of painful experience here).
-------------------------------------------
but I really need a short term bodge. http://www.access-programmers.co.uk/ubb/frown.gif
165
234x412
56x5
1000
and also some blank entries.
The problem is that I want to sort the query by these fields numerically so that:
1000 > 200
and 100x45 > 90x15
(string sort returns "200" > "1000" and "90x15" > "100x45", of course.)
I'm doing ORDER BY CInt(fieldname)
But it dies on any fields with the "x" in (i.e. not pure numeric):
'Data type mismatch in criteria expression'
Also, in any recordsets containing blank entries in the field I am sorting on, I get this error:
'Invalid use of Null'
CInt seems rather unforgiving. Are there alternatives I can use in SQL queries which will assign zero to a null text string, and fail gracefully when non-numeric characters are present?
Or can I add a custom conversion routine (how?)
e.g. IdealConversion("145x56") returns 145
Or is reworking the database (split nnnxmmm into two separate numeric fields, add zeros in all blank fields) the only way forward.
I notice DavidR said in another thread:
-------------------------------------------
Depending on your database design, it seems to me you'd be better off storing alpha, numeric, and date data in separate fields with appropriate data types. You're probably going to find it MUCH more usable in the future (I speak from the voice of painful experience here).
-------------------------------------------
but I really need a short term bodge. http://www.access-programmers.co.uk/ubb/frown.gif