Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
alina_costin
Starting Member
8 Posts |
Posted - 2003-10-07 : 07:36:57
|
| Hi!I'm trying to insert in a table : #unire_nomen_investig values from other two table : nomen investigThis is my code : create table #unire_nomen_investig (ccod varchar(8) PRIMARY KEY,cdenum varchar(130)) insert into #unire_nomen_investig select ccod cdenum from nomen n where not exists (select u1.ccod from #unire_nomen_investig u1 u1.ccod=n.ccod ) union all select ccod,cdenum from investig i where not exists (select u2.ccod from #unire_nomen_investig u2 where u2.ccod=i.ccod) something is wrong because i get an error in profiler :"Insert Error: Column name or number of supplied values does not match table definition."Thanks!Alina Costin |
|
|
Amethystium
Aged Yak Warrior
701 Posts |
Posted - 2003-10-07 : 08:19:44
|
You have a missing comma.insert into #unire_nomen_investig select ccod , cdenum from nomen n where not exists (select u1.ccod from #unire_nomen_investig u1 u1.ccod=n.ccod ) union allselect ccod,cdenum from investig i where not exists (select u2.ccod from #unire_nomen_investig u2 where u2.ccod=i.ccod __________________Make love not war! |
 |
|
|
alina_costin
Starting Member
8 Posts |
Posted - 2003-10-07 : 08:27:25
|
| Thank you. I corrected the sintax,but it seems that i didn't succeed to insert unique values because i get the next error."Violation of PRIMARY KEY constraint 'PK__#unire_nomen_inv__64ADC274'. Cannot insert duplicate key in object '#unire_nomen_investig_000100000137'.The statement has been terminated."Alina Costin |
 |
|
|
mohdowais
Sheikh of Yak Knowledge
1456 Posts |
Posted - 2003-10-07 : 09:27:05
|
Use UNION instead of UNION ALL...UNION (without the ALL) will remove duplicate rows and save the primary key violation headache.Owais Make it idiot proof and someone will make a better idiot |
 |
|
|
alina_costin
Starting Member
8 Posts |
Posted - 2003-10-08 : 03:56:34
|
| Thank you!Alina Costin |
 |
|
|
|
|
|