|
I hope the OP reports back.Apologies for not responding last Friday, due to my Mon-Thurs work-week, and my work email is not accessible from home.
No mention of which row to choose if there are multiple equidistant
values found. Or maybe there is a unique index on ColumnA?
... covered the equidistant values scenario (where 1580 was equidistant between 1560 (row# 7) and 1600 (row# 5). I did not mention whether the values would be unique. There is no index to ensure that they would be unique.... If there were two rows where the difference from the
target value is the same (like if row 7 was added where ColumnA was
1560), I'd prefer the larger ColumnA value.
SELECT my.*, abs( DBVAL - :TestVal ) as delta FROM MYILE my ORDER BY... handled the small set of rows quite elegantly. With the "ORDER BY delta, DBVAL desc" modification, I was able to ensure the desired larger value would be returned when two rows had ColumnA values equidistant from the target value. And the "fetch first row only" takes care of duplicate values of ColumnA.
delta fetch first row only
From the data...ROW# COLUMNA
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.