Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DELETING FROM A SELECT QUERY 1

Status
Not open for further replies.

klornpallier

Technical User
Aug 28, 2002
98
GB
I have the query below what gives me the records I desire. I easily need to delete all of these records. How would I do this with a DELETE FROM clause or a PL/SQL cursor? Any help would be appreciated!

SELECT ded.emp_no , re.pay_group
, ded.element
,ded.bal_increasing_cash
,ded.bal_increasing_units
,ded.pay_stop_date
FROM psadmin.payded_condition ded
,psadmin.refno re
WHERE NOT EXISTS
(SELECT 1 FROM psadmin.award_element awd
,psadmin.position_element pos
WHERE (ded.element = awd.element
OR ded.element = pos.element)
AND awd.award = 'CAR')
AND ded.emp_no = re.payroll_emp_no
AND pay_group IN ('CRE', 'HME')
AND (ded.bal_increasing_cash = 0
OR bal_increasing_units = 0)
AND perm_cash = 0
 

Try something similar to this:
Code:
DELETE FROM psadmin.payded_condition d0
 WHERE (d0.emp_no, d0.element) = (
        SELECT ded.emp_no, ded.element 
          FROM psadmin.payded_condition ded 
                 ,psadmin.refno        re 
                 WHERE NOT EXISTS 
                (SELECT 1 FROM psadmin.award_element  awd 
                            ,psadmin.position_element pos 
          WHERE (ded.element = awd.element 
                  OR ded.element = pos.element)
                  AND awd.award = 'CAR')  
                AND ded.emp_no = re.payroll_emp_no 
                AND pay_group IN ('CRE', 'HME') 
                AND (ded.bal_increasing_cash = 0
                OR bal_increasing_units = 0)
                AND perm_cash = 0)
/
[3eyes]





----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 

PS: Maybe replace the ...

WHERE (d0.emp_no, d0.element) = (

With

WHERE (d0.emp_no, d0.element) IN (



----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top