Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

how to check the previous records and after records

$
0
0

Hello everyone,

Need help in the following scenario

Everyday we get blood donations, i need to check the test_results for that donations and needs to update status.


JAN  09  statusA   (Here, we dont have result)       A (Here, we dont have result)       A1 ( got result change   A - A1)

JAN  15  status A   (Here, we dont have result)      A1(Here, we got result on jan21)    A2 (then change this to A1-A2

 

on JAN  21   GOT result ofjan 15 donation, change status A toA1.

on JAN 25    GOT result of jan 09 donation, set this donation to A1 AND change status ofjan 15 donation status A1 to A2

my question is how can we write a code, to check the previous donation's and after donation's of that particular donor and check the results of that donations and update the statuses

Note: If the 2<sup>nd</sup> unit get the test_result first, then 2<sup>nd</sup> unit should be set to A1, until 1<sup>st</sup> unit get test_results, and once the 1<sup>st</sup> unit get the test_results , then 2<sup>nd</sup> unit status should change to A2 and 1<sup>st</sup> unit status should be A1.

 

 donation_number,donor_number,donation_date,status column's,days_since_last_donation are indonation table.

 donation_number,donor_number,donation_date,test_result_date,test_code column's are inTest_Results table.

  1. IF days_since_last_donation =0  in donation_table for this donation.   Set this status to A1.
  1. IF days_since_last_donation between 1 - 180 in donation_table for this donation. CHECK for the previous donation of that particular donor, if PPTA_status = A. Set this status to A1.
  2. if we get test results of the 1st donation later to 2nd donation, then 1st donation should set status to A1 and 2nd donation statuschange A1 to A2.

days_since_last_donation 0 means first time donation. (donor donating 1st time).

days_since_last_donation between 1 and 180 means second time donation. (donor donating 2nd time).


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>