Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL delete procedure

Posted on 2011-02-12
3
Medium Priority
?
277 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
[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
  • 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 1000 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 1000 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

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

722 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