Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL delete procedure

Posted on 2011-02-12
3
Medium Priority
?
278 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 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

885 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