function VarToSql(value: Variant): string;
begin
if (varisnull(value)) or (varisempty(value)) then
Result:='NULL'
else
case Vartype(value) of
varDate:
begin
Result:=Quotedstr(Datetimetostr(VartoDatetime(value)));
if Result ='' then
begin
Result :='NULL';
end;
end;
varString,varOlestr:
Result:=Quotedstr(Trim(Vartostr(value)));
varboolean:
begin
if value then
Result:='1'
else
Result:='0';
end;
varSmallint,varInteger,varDouble,varShortInt,varInt64:
if Copy(Vartostr(value),1,1)='-' Then
begin
Result:=Trim('(-1)*'+Copy(Vartostr(value),2,length(Vartostr(value))-1));
end
else
begin
Result:=Trim(Vartostr(value));
end;
varLongWord,varCurrency:
Result:=Trim(Vartostr(value));
else
Result:=Quotedstr(Trim(Vartostr(value)));
end;
end;