Subject | insert and select with Union |
---|---|
Author | Marco Menardi <mmenaz@lycosmail.com> |
Post date | 2002-12-28T23:37:16Z |
Hi, I've a insert into mytable (x,y,z) select a, b, c and it works.
But now I've to add a union, and it does not work anymore (error:
token unknow "union").
The select part is ok, since if I run it alone (without the INSERT) it
returns a correct recordset with no SQL error.
why:
insert into mytable (x,y,z)
select a, b, c
from Atable
UNION
select a, b, c
from Btable
does not work? Is there any syntax trick, or UNION has to be avoided here?
thanks
Marco Menardi
(the true SQL is the following:
INSERT INTO WK_SELEZIONI (COD_SELEZIONE, COD_SELEZIONE_SEC,
COD_UTENTE, VAL_SN, CLIENTE_ID)
SELECT 'D', 'CL', 'marco', 'S'
, UNITA_U_CLIENTI.CLIENTE_ID
FROM UNITA_U_CLIENTI
WHERE (EXISTS (SELECT * FROM UNITA_IMMOBILIARI
WHERE (CONDOMINIO_ID = 'CIRM') AND
(UNITA_IMMOBILIARI.UNITAIMM_ID=UNITA_U_CLIENTI.UNITAIMM_ID) ))
AND (UNITA_U_CLIENTI.ESERCIZIO_ID STARTING WITH '000000')
AND (UNITA_U_CLIENTI.INVIA_CONVOCAZIONE='S')
UNION
SELECT 'D', 'CL', 'marco', 'S'
, UICC_INFORMATI.CLIENTE_ID
FROM UICC_INFORMATI
WHERE (EXISTS (SELECT * FROM UNITA_IMMOBILIARI
INNER JOIN UNITA_U_CLIENTI ON
(UNITA_IMMOBILIARI.UNITAIMM_ID=UNITA_U_CLIENTI.UNITAIMM_ID)
WHERE (CONDOMINIO_ID = 'CIRM') AND
(UICC_INFORMATI.UICC_ID=UNITA_U_CLIENTI.UICC_ID) ))
AND (UICC_INFORMATI.INVIA_CONVOCAZIONE='S')
But now I've to add a union, and it does not work anymore (error:
token unknow "union").
The select part is ok, since if I run it alone (without the INSERT) it
returns a correct recordset with no SQL error.
why:
insert into mytable (x,y,z)
select a, b, c
from Atable
UNION
select a, b, c
from Btable
does not work? Is there any syntax trick, or UNION has to be avoided here?
thanks
Marco Menardi
(the true SQL is the following:
INSERT INTO WK_SELEZIONI (COD_SELEZIONE, COD_SELEZIONE_SEC,
COD_UTENTE, VAL_SN, CLIENTE_ID)
SELECT 'D', 'CL', 'marco', 'S'
, UNITA_U_CLIENTI.CLIENTE_ID
FROM UNITA_U_CLIENTI
WHERE (EXISTS (SELECT * FROM UNITA_IMMOBILIARI
WHERE (CONDOMINIO_ID = 'CIRM') AND
(UNITA_IMMOBILIARI.UNITAIMM_ID=UNITA_U_CLIENTI.UNITAIMM_ID) ))
AND (UNITA_U_CLIENTI.ESERCIZIO_ID STARTING WITH '000000')
AND (UNITA_U_CLIENTI.INVIA_CONVOCAZIONE='S')
UNION
SELECT 'D', 'CL', 'marco', 'S'
, UICC_INFORMATI.CLIENTE_ID
FROM UICC_INFORMATI
WHERE (EXISTS (SELECT * FROM UNITA_IMMOBILIARI
INNER JOIN UNITA_U_CLIENTI ON
(UNITA_IMMOBILIARI.UNITAIMM_ID=UNITA_U_CLIENTI.UNITAIMM_ID)
WHERE (CONDOMINIO_ID = 'CIRM') AND
(UICC_INFORMATI.UICC_ID=UNITA_U_CLIENTI.UICC_ID) ))
AND (UICC_INFORMATI.INVIA_CONVOCAZIONE='S')