Subject RE: [firebird-support] INSERT INTO SELECT only inserts one row
Author Rick Debay
Properly aliasing the query still has the problem with inserting only
one row.

INSERT INTO
INVC_GRANTEE_INVT (GRANTEE_INVOICE, CHC, PHARMACY, GROUPID, NDC,
START_QTY, CLM_QTY, RPL_QTY, BO_QTY)
SELECT
179, igi.CHC, igi.PHARMACY, igi.GROUPID, igi.NDC, igi.END_QTY, 0, 0,
0
FROM
INVC_GRANTEE_INVT igi
WHERE
igi.END_QTY <> 0 AND
/* get the last inventory statement for this grantee */
igi.GRANTEE_INVOICE = (
SELECT
MAX(invt.GRANTEE_INVOICE)
FROM
INVC_GRANTEE_INVT invt
JOIN INVC_GRANTEE_INVC invc
ON invc.ID = invt.GRANTEE_INVOICE
WHERE
/* from the given invoice, get the grantee */
invc.GRANTEE = (
SELECT
igi2.GRANTEE
FROM
INVC_GRANTEE_INVC igi2
WHERE
igi2.ID = 179 ))