Hello I have this peice of code that I would like to make pure sql and
I am not sure what the best way to do this would be.
What i am trying to do is:
1. look in the block table if its in there then delete it from irs_rawdata
2. look in irs_rawdata for match of rules (WHERE) and insert into query
3. take the rest of irs_rawdata and insert into block the EIN into a
field called fin and also add a value to the who_blocked field
S-123456789
4. delete the records that was added to the block table from the
irs_rawdata table so its empty
to my best ablility the below code appears to work but I know this
code could be rewriten to be better.
Sincerely,
Christopher
the code is:
-----------------------------------------------------------------------------------------------------------------------------------------------
DELETE FROM irs_rawdata
WHERE EXISTS
(
SELECT fin
FROM block
);
INSERT INTO query SELECT * FROM irs_rawdata
WHERE
PNO LIKE '%blind%' OR
PNO LIKE '%deaf%' OR
NTEE_Code LIKE '%P87%';
INSERT INTO block SELECT EIN FROM irs_rawdata
WHERE NOT EXISTS
PNO LIKE '%blind%' OR
PNO LIKE '%deaf%' OR
NTEE_Code LIKE '%P87%';
DELETE FROM irs_rawdata
WHERE NOT EXISTS
(
SELECT PNO, Activity_Code, NTEE_code
FROM irs_rawdata
WHERE
PNO LIKE '%blind%' OR
PNO LIKE '%deaf%' OR
NTEE_Code LIKE '%P87%'
);