I have a field area in table property, in this field records are saved in 1-0-3-4, 0-4-2-0 and so on. In each record 1st represent the Highest denomination of area, second represent the second highest, third – the third highest and last, i.e. fourth denote the lowest denomination of an area. The format x-x-x-x is how the area of a land or property is denoted in our country.
Searching above field for exact match is not a problem, but what if I have to show results with nearest match as well. Like , 1-0-3-3, 1-0-4-4,1-0-3-5 are the nearest match with 1-0-3-4
Is it possible?
Thanks
It’s possible, but messy. It would help if you could normalize the “area” field into individual columns – it would make the solution neater and much faster!
An example implementation might be:
This assumes that the distance between areas is the same for any of the values in a given column. If that’s not the case, you can refine it by retrieving the code (through SUBSTRING) and doing whatever arithmetic on it that you need.
If you convert area to individual columns, this becomes easier and nicer, as well as faster (the last query in the above union will be slow, because it can’t use the index all that efficiently).
For instance: