以下效果很好:
SELECT ‘K’ CONCAT CHAR(PNR), FIRSTNAME, LASTNAME
FROM S654321.PERSON P
WHERE NOT EXISTS(SELECT *
FROM S654321.CUSTOMER C
WHERE C.FIRSTNAME = P.FIRSTNAME AND C.LASTNAME = P.LASTNAME)
我想在我的插页中使用此选择作为子选择:
INSERT INTO S654321.CUSTOMER
VALUES(SELECT ‘K’ CONCAT CHAR(PNR), FIRSTNAME, LASTNAME
FROM S654321.PERSON P
WHERE NOT EXISTS(SELECT *
FROM S654321.CUSTOMER C
WHERE C.FIRSTNAME = P.FIRSTNAME
AND C.LASTNAME = P.LASTNAME))
但这句话不起作用。
CUSTOMER具有以下结构:
答案 0 :(得分:1)
在这种情况下,您不需要使用VALUES语句。试试这个
INSERT INTO S654321.CUSTOMER (KNR, FIRSTNAME, LASTNAME)
SELECT ‘K’ CONCAT CHAR(PNR), FIRSTNAME, LASTNAME
FROM S654321.PERSON P
WHERE NOT EXISTS(SELECT *
FROM S654321.CUSTOMER C
WHERE C.FIRSTNAME = P.FIRSTNAME
AND C.LASTNAME = P.LASTNAME)