Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have tabel fields like 'price varchar(30)'

In that field i have values like

price

10lakhs
20lakhs
13crores
15crores

now i want to retrieve the values using between operator based on the user choice.(if user enter minprice as 10lakhs and maxprice as 20lakhs or minpprice:13crores and maxprice:15crores from frontend side then i need to display the records between above prices).
SQL
price between '10lakhs' and '20lakhs' and ((price like '__ crores') or (pprice like '__ lakhs'))


It is displaying both lakhs and crores records.

Result:


SQL
10lakhs
20lakhs
13crores
15crores
Posted

1 solution

Rule one of data comparisons: always store numeric values in numeric fields.

When you compare two strings, it uses a string comparison, not a numeric one. This means each character is inspected one by one to see which is "higher" than the other. So a string comparison will be ordered as:
tect
"1"
"10"
"11"
...
"2"
"20"
...
and so forth.

Change your database. Store numbers in numeric fields, and dates in date based field. Only ever store string values in string fields or you will get loads of awkward, annoying errors which are hard to code round - and completely unnecessary.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900