Solved

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

Posted on 2007-03-24
3
264 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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 to return specific rows and columns, with various degrees of sorting and limits in place.

739 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