Solved

Need Qry Syntax Help - Need to delete two records that are exactly the same

Posted on 2007-03-24
3
260 Views
Last Modified: 2010-03-19
I accidentally inserted two records that are exactly the same into a MS SQL (2005) table.  I can't delete them using the following qry:

Delete from Competitors where CompetitorID=66 and SeasonID=12 and EventID=0 and RunID=6

When I run the qry, it says 0 rows affected.  The only way I know how to fix this is truncate the table and then reinsert the data.  Is there another way, because there is no way I want to risk the data.

Thanks in advance!

Regards,
Eric
0
Comment
Question by:indy500fan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 300 total points
ID: 18784981
>Delete from Competitors where CompetitorID=66 and SeasonID=12 and >EventID=0 and RunID=6
>When I run the qry, it says 0 rows affected.
then, your where clause is not correct.

can you please show the query that returns the data of the 2 rows (SELECT)?
I would use the following technique to delete a single row (even if there are several rows):
SET ROWCOUNT 1
DELETE Competitors  WHERE ...
SET ROWCOUNT 0
0
 
LVL 10

Assisted Solution

by:lahousden
lahousden earned 200 total points
ID: 18784988
If you are sure that these are the identifying values for these columns for the rows in question then it looks like you don't have the problem you think you have.  Change the "Delete" to a "Select * " in your SQL statement and see whether in fact you still have the troublesome rows in your table, i.e.

Select * from Competitors where CompetitorID=66 and SeasonID=12 and EventID=0 and RunID=6
0
 

Author Comment

by:indy500fan
ID: 18785143
angellll,
Well after trying to duplicate, I can't.
Thanks,
Eric
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question