|
Question : SQL Insert statement with a composite key
|
|
I am trying to write an INSERT statement in order to insert values from one table that are not present in another table. The primary key is a composite key of 2 fields, PRODUCTNAME, SUBID6. Theorectically, when I'm done, the tables should be the same size. This is my statement I have written. I believe my problem is with trying to link my PRODUCTNAME and SUBID6 as the primary key.
INSERT INTO IVRCONTROLNY ( PRODUCTNAME, FUNDNAMEOLD, FUNDNAME, WINFLEXNAME, SUBID, ACTIVE, SUBID6, ADMINSYSTEM, WEBID ) SELECT IVRCONTROLNYVIPS.PRODUCTNAME, IVRCONTROLNYVIPS.FUNDNAMEOLD, IVRCONTROLNYVIPS.FUNDNAME, IVRCONTROLNYVIPS.WINFLEXNAME, IVRCONTROLNYVIPS.SUBID, IVRCONTROLNYVIPS.ACTIVE, IVRCONTROLNYVIPS.SUBID6, IVRCONTROLNYVIPS.ADMINSYSTEM, IVRCONTROLNYVIPS.WEBID FROM IVRCONTROLNYVIPS WHERE IVRCONTROLNYVIPS.SUBID6 NOT IN (SELECT SUBID6 FROM IVRCONTROLNY) AND IVRCONTROLNYVIPS.PRODUCTNAME NOT IS (SELECT PRODUCTNAME FROM IVRCONTROLNY);
|
|
Answer : SQL Insert statement with a composite key
|
|
INSERT INTO IVRCONTROLNY ( PRODUCTNAME, FUNDNAMEOLD, FUNDNAME, WINFLEXNAME, SUBID, ACTIVE, SUBID6, ADMINSYSTEM, WEBID ) SELECT i.PRODUCTNAME, i.FUNDNAMEOLD, i.FUNDNAME, i.WINFLEXNAME, i.SUBID, i.ACTIVE, i.SUBID6, i.ADMINSYSTEM, i.WEBID FROM IVRCONTROLNYVIPS i WHERE NOT EXISTS ( SELECT NULL FROM IVRCONTROLNY o WHERE o.SUBID6 = i.SUBID6 AND o.PRODUCTNAME = i.PRODUCTNAME )
|
|
|
|