Solved

SQL delete procedure

Posted on 2011-02-12
3
268 Views
Last Modified: 2012-05-11
I have a table that I am trying to clean up using a delete procedure.
Table name is TR
Columns are TR_ID,EmployeeID,TrainingID
I need to delete the row where the employee has a record with TrainingID = 171 ONLY if the employee has a record with a TrainingID = 113

Any help would be appreciated.
0
Comment
Question by:AkAlan
  • 2
3 Comments
 
LVL 16

Expert Comment

by:BurnieP
ID: 34879916
DELETE FROM TR WHERE TrainingID = 171 AND (SELECT COUNT(*) FROM TR TR2 WHERE TR2.TR_EmployeeID = TR.EmployeeID) > 0
0
 
LVL 23

Assisted Solution

by:wdosanjos
wdosanjos earned 250 total points
ID: 34879918
Should be something like:

DELETE TR
WHERE TrainingID = 171
and exists (select 1 from TR as TR2 where TR2.EmployeeID = TR.EmployeeID and TR2.TrainingID = 113)
0
 
LVL 16

Accepted Solution

by:
BurnieP earned 250 total points
ID: 34879919
Sorry, forgot a part :

DELETE FROM TR WHERE TrainingID = 171 AND (SELECT COUNT(*) FROM TR TR2 WHERE TR2.TR_EmployeeID = TR.EmployeeID AND TrainingID = 113) > 0
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now