rwv
asked on
How to update null field with SQL?
This update function works fine for non-null values, but it won't work if the field requests is null. How do I fix it?
function IncRequests(trkid : integer) : boolean;
var ok : boolean;
q : TQuery;
begin
ok := false;
q := TQuery.Create(nil);
try
if trkid > 0 then
begin
q.SQL.Clear;
q.SQL.Add('update tracks.db set requests = requests + 1 '+
'where id = '+inttostr(trkid));
q.ExecSQL;
ok := true;
end;
finally
q.Free;
end;
IncRequests := ok;
end;
function IncRequests(trkid : integer) : boolean;
var ok : boolean;
q : TQuery;
begin
ok := false;
q := TQuery.Create(nil);
try
if trkid > 0 then
begin
q.SQL.Clear;
q.SQL.Add('update tracks.db set requests = requests + 1 '+
'where id = '+inttostr(trkid));
q.ExecSQL;
ok := true;
end;
finally
q.Free;
end;
IncRequests := ok;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Unfortunatly not, Bobby. I also wish it was possible, but so far, it's not.
Alex
Alex
ASKER
Is it possible to use an if then statement in sql?
ie -
if requests is null then requests = 1
else requests = requests + 1
Bobby