Jump to content

[SOLVED] Parsing data with SQL only!


spiritssight

Recommended Posts

Hello I have this piece of code that I would like to make pure sql and I am not sure what the best way to do this would be.

 

Please assist with this as its for a non-profit project.

 

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 rewritten to be better.

 

Sincerely,

Christopher

 

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%'
);

Link to comment
https://forums.phpfreaks.com/topic/89311-solved-parsing-data-with-sql-only/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.