Abraham Olatubosun

Abraham Olatubosun

  • NA
  • 471
  • 107.1k

How to Perform Multiple Task in T-SQL

Jul 26 2017 5:32 PM
Dear Code Masters,
 
    Hope this mail meet you all in good health. Please i will aprecaite any workable solution to my question.
 
I want to create a single store procedure that i want to INSERT to a table based on some crateria, after then use this table new record to update itself based on other crateria
E.g :
 
  1. use IQCARE  
  2. INSERT INTO tbl_ARTSTARTDATE_TABLE (ptn_pk,PatientID,HospitalNumber,Sex,AgeAtStartART,DOB,ARTStartDate,ArtStatus )  
  3. (select ptn_pk,PatientID,HospitalNumber,Sex,AgeAtStartART,DOB,ARTStartDate,ArtStatus from  tbl_RADET_TABLE)  
the above code works, i want to use the PTN_PK to update tbl_ARTSTARTDATE_TABE based on the crateria specied as shown below :
 
  1. UPDATE tbl_ARTSTARTDATE_TABLE a SET LastPickupDate =(Select  top 1 DispensedByDate from VW_PatientPharmacy b Where  b.Ptn_pk =a.Ptn_pk  
  2. and DispensedByDate is not null order by DispensedByDate desc)  
I want all the commands to be in one Stored Procedure.
 
Thank you all 

Answers (2)