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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with SQL 1

Status
Not open for further replies.

alexhu

MIS
Sep 25, 2001
1,288
GB
I have 2 tables

one containing headers (ahasnf00)

the other containing detail (adasnf00)

I need to purge both, but cannot work out how to purge the detail table.

The connection between the 2 tables is shipment number

as in the following SQL

select b.AD00_SHIPMENT_NBR
from ahasnf00 a, adasnf00 b
where a.AH00_VERIFIED_DATE like '%&DATE'
and
a.AH00_STATUS_CODE >= '50'
and
a.AH00_SHIPMENT_NBR=b.AD00_SHIPMENT_NBR
/

This works OK and gives me the correct numbers, but how do I

a) insert these records into another table
b) delete thenm from the detail table

Alex
 
Is this what you want to do ?

insert into temp_table(shipment_nbr)
select b.AD00_SHIPMENT_NBR
from ahasnf00 a, adasnf00 b
where a.AH00_VERIFIED_DATE like '%&DATE'
and
a.AH00_STATUS_CODE >= '50'
and
a.AH00_SHIPMENT_NBR=b.AD00_SHIPMENT_NBR
/

delete from adasnf00
where adoo_shipment_nbr in
(select shipment_nbr from temp_table)
/
 
Alex,

how about this

Code:
CREATE TABLE results
AS
SELECT
      b.AD00_SHIPMENT_NBR
FROM
      ahasnf00 a, adasnf00 b
WHERE
      a.AH00_VERIFIED_DATE like '%&DATE'
AND
      a.AH00_STATUS_CODE >= '50'
AND
      a.AH00_SHIPMENT_NBR=b.AD00_SHIPMENT_NBR
/
DELETE
FROM adasnf00 
WHERE (AD00_SHIPMENT_NBR) IN
  (
   SELECT
          a.AD00_SHIPMENT_NBR
   FROM   ahasnf00 a,
          adasnf00 b
   WHERE
          a.AH00_VERIFIED_DATE like '%&DATE'
   AND
          a.AH00_STATUS_CODE >= '50'
   AND
          a.AH00_SHIPMENT_NBR = b.AD00_SHIPMENT_NBR
   )
/

Hope this makes sense
 
Dagon - fine thanks the principle is there (its a little more involved than I made out, but I have the basics now)

Thanks

Alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top