SELECT MAX(code) FROM mytable WHERE code < [1101002]and this for your second one
SELECT myfield FROM mytable WHERE myfield == LEFT([1101002],4)now make those two select available in different functions maybe called 'searchnearestbelow' and 'checkparentnode'. Both Functions receive the base node as parameter and deliver the found node by return value.