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 |
|
Andreww
Starting Member
1 Post |
Posted - 2001-12-17 : 20:03:44
|
| SQL question...#Temp has an int column 'id'#Temp has a unique index on 'id' with IGNORE_DUP_KEY set.TblA has an int column 'id' as well as various other columns.For the sake of example say #Temp has 1000 rows. Some of which have the same 'id' value as rows in TblA. So the following statement completes successfully yet returns "duplicate key was ignored". Which makes sense considering the index on #Temp.id.INSERT INTO #Temp (id) SELECT id FROM TblA WHERE Coln IS NULL If the above code is changed slightly this should (in theory) alleviate the "duplicate key was ignored" error altogether.INSERT INTO #Temp (id) SELECT id FROM TblA WHERE Coln IS NULL AND TblA.id NOT IN (SELECT id FROM #Temp)In my SP this statement is executed many times with Coln being changed each time. And it's still returning the "duplicate key was ignored" error. Any help would be so appreciated. I have lost all my hair to this SP. |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2001-12-17 : 22:26:49
|
| Probably duplicate id's in tblAINSERT INTO #Temp (id) SELECT distinct id FROM TblA WHERE Coln IS NULL AND TblA.id NOT IN (SELECT id FROM #Temp)==========================================Cursors are useful if you don't know sql.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|