Subject RE: [firebird-support] delete min
Author Leyne, Sean
Hans,

> Apart from the fact that I think what you want is a bit strange-
imagine
> a patient that came in for the first time yesterday, and was given a
> first treatment, the record describing this would be deleted today!
> But apart from that, I am afraid the only thing to do what you want is
> to create a stored procedure, like this:
>
> declare MINDATE date;
> declare NUMPAT integer;
> begin
> for SELECT MIN("DATE") as MINDATE
> FROM MYTABLE
> group by NUMPAT
> into :MINDATE, :NUMPAT do
> delete from MYTABLE where "DATE" = :MINDATE and NUMPAT = :NUMPAT;
> end


You don't have to create an SP; you can use the EXECUTE BLOCK
functionality.

EXECUTE BLOCK AS
declare MINDATE date;
declare NUMPAT integer;
begin
for
SELECT NUMPAT, MIN("DATE") as MINDATE
FROM MYTABLE
group by 1
into
:MINDATE, :NUMPAT
Do
BEGIN
delete from MYTABLE where "DATE" = :MINDATE and NUMPAT = :NUMPAT;
END
end


Sean

P.S. Please note the corrections I made to your example.