Hi all,
I am somewhat new to sql server. So help me in whatever way you can.
I have two tables one of which doesnt have a primary key(table A) and other has a composite key formed of two columns(table B). I need to insert entries in table B from table A(table A has a unique constratint UID which is passed to table B). Table B also has a unique ID which is different from UID of table A.
Sometimes table A tries to insert a duplicate entry which is denied by table B since it has a primary key.
The insert query is as below.
table A - CORE
table B - CRF
INSERT INTO CRF (CORE_UID,ACCT_ NUM_MIN, ACCT_NUM_MAX,BI N, BUS_ID,BUS_NM,I SO_CTRY_CD, REGN_CD, PROD_TYPE_CD, CARD_TYPE)
(SELECT UID,LEFT(ACCT_N UM_MIN,16),LEFT ( ACCT_NUM_MAX,16 ),BIN, BUS_ID,BUS_NM,I SO_CTRY_CD, REGN_CD, PROD_TYPE_CD, CARD_TYPE FROM CORE WHERE UID NOT IN (SELECT CORE_UID FROM CRF))
I am not worried about the performance. I have tried if not exists and except but since i am new i am not able to figure out the problem.
Thank you in advance for all who try to help me out.
I am somewhat new to sql server. So help me in whatever way you can.
I have two tables one of which doesnt have a primary key(table A) and other has a composite key formed of two columns(table B). I need to insert entries in table B from table A(table A has a unique constratint UID which is passed to table B). Table B also has a unique ID which is different from UID of table A.
Sometimes table A tries to insert a duplicate entry which is denied by table B since it has a primary key.
The insert query is as below.
table A - CORE
table B - CRF
INSERT INTO CRF (CORE_UID,ACCT_ NUM_MIN, ACCT_NUM_MAX,BI N, BUS_ID,BUS_NM,I SO_CTRY_CD, REGN_CD, PROD_TYPE_CD, CARD_TYPE)
(SELECT UID,LEFT(ACCT_N UM_MIN,16),LEFT ( ACCT_NUM_MAX,16 ),BIN, BUS_ID,BUS_NM,I SO_CTRY_CD, REGN_CD, PROD_TYPE_CD, CARD_TYPE FROM CORE WHERE UID NOT IN (SELECT CORE_UID FROM CRF))
I am not worried about the performance. I have tried if not exists and except but since i am new i am not able to figure out the problem.
Thank you in advance for all who try to help me out.
Comment