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 |
mana
Posting Yak Master
102 Posts |
Posted - 2014-09-24 : 04:44:13
|
how should i use not existscan you help me please?for example the below code doesn't worki have 5 primary keys : datum, teil,id,workcenter and reason-codehelloi have the below code and it has errro for primary keycan you help me pleasE?in both dbo.Table_2 and dbo.Bewegungen_Inventur_Korrekturen Datum_Bewegung and Teil_Nummerand Workcenterand Reason_Codeand Id_Nrare primary key togetherthank youinsert into dbo.Table_2 SELECT b.Datum_Bewegung, b.Teil_Nummer, b.Workcenter, b.Reason_Code, b.Menge, b.Id_Nr, b.Mengeneinheit FROM dbo.Bewegungen_Inventur_Korrekturen b WHERE not exists (SELECT * FROM dbo.Table_2 a WHERE b.Datum_Bewegung = a.Datum_Bewegung and b.Teil_Nummer=a.Teil_Nummerand b.Workcenter=a.Workcenterand b.Reason_Code=a.Reason_Codeand b.Id_Nr=a.Id_Nr) |
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2014-09-24 : 11:46:20
|
The code *seems* right. Could it be that your source table (Bewegungen_Inventur_Korrekturen) has duplicates? I'd also use an explicit column list for the INSERT; it is a best practice. Too often we enjoy the comfort of opinion without the discomfort of thought. - John F. Kennedy |
|
|
|
|
|