Click to See Complete Forum and Search --> : PURE sql filtering script, works but looking for improvments!


spiritssight
02-04-2008, 11:59 PM
Hello All,

I have taken what others have suggested and was able to rewrite the script using only sql so that I could do it with a few other scripts that do thing automaticaly, like grabbing file from a site, unzipping, uploading and now it will do the filter all in one shot and use mostly only one server at a time when running the script.

Any how here is the code that I have come up with and I would like any feed back on making it better:

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
PNO LIKE '%braille%' OR
PNO LIKE '%sight%' OR
PNO LIKE '%vision%' OR
PNO LIKE '%sign%' OR
PNO LIKE '%ear%' OR
PNO LIKE '%eye%' OR
PNO LIKE '%dog%' OR
Activity_Code LIKE '%031%' OR
NTEE_Code LIKE '%G41%' OR
NTEE_Code LIKE '%G42%' OR
NTEE_Code LIKE '%H41%' OR
NTEE_Code LIKE '%H42%' OR
NTEE_Code LIKE '%P86%' OR
NTEE_Code LIKE '%P87%';

DELETE FROM irs_rawdata
WHERE
PNO LIKE '%blind%' OR
PNO LIKE '%deaf%' OR
PNO LIKE '%braille%' OR
PNO LIKE '%sight%' OR
PNO LIKE '%vision%' OR
PNO LIKE '%sign%' OR
PNO LIKE '%ear%' OR
PNO LIKE '%eye%' OR
PNO LIKE '%dog%' OR
Activity_Code LIKE '%031%' OR
NTEE_Code LIKE '%G41%' OR
NTEE_Code LIKE '%G42%' OR
NTEE_Code LIKE '%H41%' OR
NTEE_Code LIKE '%H42%' OR
NTEE_Code LIKE '%P86%' OR
NTEE_Code LIKE '%P87%';


INSERT INTO block (`fin`, `who_blocked`)
SELECT EIN, 'S-123456789' FROM irs_rawdata
WHERE
PNO NOT LIKE '%blind%' OR
PNO NOT LIKE '%deaf%' OR
PNO NOT LIKE '%braille%' OR
PNO NOT LIKE '%sight%' OR
PNO NOT LIKE '%vision%' OR
PNO NOT LIKE '%sign%' OR
PNO NOT LIKE '%ear%' OR
PNO NOT LIKE '%eye%' OR
PNO NOT LIKE '%dog%' OR
Activity_Code NOT LIKE '%031%' OR
NTEE_Code NOT LIKE '%G41%' OR
NTEE_Code NOT LIKE '%G42%' OR
NTEE_Code NOT LIKE '%H41%' OR
NTEE_Code NOT LIKE '%H42%' OR
NTEE_Code NOT LIKE '%P86%' OR
NTEE_Code NOT LIKE '%P87%';


DELETE FROM irs_rawdata;


Sincerely,
Christopher

spiritssight
02-05-2008, 12:04 AM
I have one question about this script, how can I have it take all write spaces out of it when it inserts into query? I know I can use TRIM() but I am not sure how I can use this on the insert as I am not defining the cols

Thanks for the help and feed back on the code in the above post.

Sincerely,
Christopher

spiritssight
02-05-2008, 12:15 AM
I think the answer to my question is, but I am not sure:

INSERT INTO query SELECT TRIM(*) FROM irs_rawdata
WHERE
PNO LIKE '%blind%' OR
PNO LIKE '%deaf%' OR
PNO LIKE '%braille%' OR
PNO LIKE '%sight%' OR
PNO LIKE '%vision%' OR
PNO LIKE '%sign%' OR
PNO LIKE '%ear%' OR
PNO LIKE '%eye%' OR
PNO LIKE '%dog%' OR
Activity_Code LIKE '%031%' OR
NTEE_Code LIKE '%G41%' OR
NTEE_Code LIKE '%G42%' OR
NTEE_Code LIKE '%H41%' OR
NTEE_Code LIKE '%H42%' OR
NTEE_Code LIKE '%P86%' OR
NTEE_Code LIKE '%P87%';