Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.