找出数据库中的某个域最接近给定值的上、下值
function GetNearValue(tblName,fldName,confldName,confldValue:string; GivenValue:Double;
var LowValue, HighValue:Double):Boolean;
var
s:string;
begin
Result:=False;
s:='SELECT Max_V,Min_V FROM '+
'(SELECT MAX('+fldName+') AS Max_V FROM '+tblName+
' WHERE ('+fldName+'<='+ FloatToStr(GivenValue)+') AND ('+confldName+'= '''+confldValue+''')) AS Max_Tbl,'+
'(SELECT MIN('+fldName+') AS Min_V FROM '+tblName+
' WHERE ('+fldName+'>='+ FloatToStr(GivenValue)+') AND ('+confldName+'= '''+confldValue+''')) AS Min_Tbl';
with frmDM.adoqryTmp do
begin
Close;
SQL.Clear;
SQL.Add(s);
try
Open;
if RecordCount > 0 then
begin
LowValue:=VarToFloat(FieldValues['Min_V']);
HighValue:=VarToFloat(FieldValues['Max_V']);
Close;
Result:=True;
end;
except
Close;
end;
end;
end;