If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > text and numbers

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-27-05, 04:54
luigi_cr luigi_cr is offline
Registered User
 
Join Date: Feb 2005
Posts: 2
text and numbers

Is it possible to consider numbers stored in a text field as number during a query or a sort?
In a text field the user should write text or number, it depends on another field, but during a query with a comparison as >= the number is treated like text, and the result is not what is espected.
The second field involved is used into the query, so there is no mix between text and numbers.

Thanks for any help
Reply With Quote
  #2 (permalink)  
Old 02-27-05, 10:29
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
In Oracle, you would use the TO_NUMBER function, for example:

SELECT * FROM your_table
WHERE TO_NUMBER(this_column) >= some_value;

This statement will raise an error if "this_column" contains data different than numbers (for example, values like 'abc', 'a123', '#$%' etc.). It means that you'd have to, additionally, check for column value before using this function.

Furthermore, if you have index created on column "this_column", it would then NOT be used (but there's possibility for you to create an index based on this function, which would then be used in your queries).
Reply With Quote
  #3 (permalink)  
Old 02-28-05, 18:18
ejustuss ejustuss is offline
Registered User
 
Join Date: Feb 2005
Posts: 78
There should be equivalent functions to TO_NUMBER in any database system you are using e.g. CONVERT/CAST in SQL Server. Sometimes you have to look hard to find them though. If you have a fixed length field or the data is added with blanks around it you might need to TRIM them off first.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On