CJSmith dot me

I dump stuff I find useful here

Remove invalid Datalinx WHM Report Records

Published / by Chris Smith / Leave a Comment

Where printers have been removed can cause issues with the user report program where you can control where users print to.
The code below simply looks at the printer table and compares with the report control table.
BEGIN TRAN
--Check number of records which have invalid printers
SELECT *
FROM "scheme"."wh_rctl"
WHERE NOT EXISTS
(SELECT *
FROM "scheme"."wh_pctl"
WHERE "scheme"."wh_pctl"."dp_printer" = "scheme"."wh_rctl"."dr_printer")
--THIS WILL DELETE RECORDS BE CAREFUL!
DELETE
FROM "scheme"."wh_rctl"
WHERE NOT EXISTS
(SELECT *
FROM "scheme"."wh_pctl"
WHERE "scheme"."wh_pctl"."dp_printer" = "scheme"."wh_rctl"."dr_printer")
--Check records no longer exist then commit tran
SELECT *
FROM "scheme"."wh_rctl"
WHERE NOT EXISTS
(SELECT *
FROM "scheme"."wh_pctl"
WHERE "scheme"."wh_pctl"."dp_printer" = "scheme"."wh_rctl"."dr_printer")
--Just in case
COMMIT TRAN

Leave a Reply