Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Duplicate Values

Status
Not open for further replies.

Compkitty

Programmer
Jan 7, 2005
121
US
I am doing an insert into a table and before/after I do the insert I want to run a delet on any dupes there might be in the table.. here is what i have

Code:
DELETE FROM ANI
WHERE ANIID <=
(
SELECT MAX(ANIID)
FROM ANI
WHERE ANI = ANI 
)
AND ANI = ANI

any help would be AWESOME
 
If I'm reading that code correctly, you would delete all rows in your table with the <= portion of your Where statement instead of just duplicates.

Do a Select Into from that table to set up a test table to verify your code and this code. I think your code is a bit redundant too, and would re-write your code as:

Code:
DELETE FROM ANI
WHERE ANIID <
( SELECT MAX(ANIID)
  FROM ANI )

Of course, you might want to verify this on the SQL Server Programming group forum183.

Hope that helps.




Catadmin - MCDBA, MCSA
"If a person is Microsoft Certified, does that mean that Microsoft pays the bills for the funny white jackets that tie in the back???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top