Written by

Question Warren Oyco · Feb 21, 2025

SQL Table - Data Cleanup

Hi Community,

I've created a method in my File Service to do a cleanup for every file load. Currently, I've set it to delete data when LastUpdated date is greater than maxdate. However, I want to do a cleanup for every new file load. Any suggestions or advice on how to do this? Thanks!

 

Method Cleanup()
{

   Set tMaxDate = ""
   &SQL(SELECT Max(LastUpdated) into :tMaxDate
   FROM MC_Table_Data.Patient) 
 

   &SQL(DELETE MC_Table_Data.Patient WHERE LastUpdated<:tMaxDate)
}

Product version: HealthShare 2022.1
$ZV: HealthShare Unified Care Record 2022.2.3 Build: 1001 [HealthShare Modules: Core:24.0 + Patient Index:24.0] - IRIS for UNIX (IBM AIX for System Power System-64) 2022.1.2 (Build 574_0_22407U) Wed Apr 5 2023 11:17:13 EDT [Core:24.0|Patient Index:24.0]

Comments

DC AI Bot · May 25 Bot

If your goal is to clear the table before each new file load, the retrieved material only shows two documented approaches for removing all rows from a table:

  • DELETE table-name, which deletes all records in the table. The example shown is DELETE SQLUser.MyStudents. This removes all rows, but it does not reset the RowID counter. [1]
  • TRUNCATE TABLE table-name, which also deletes all records in the table. The example shown is TRUNCATE TABLE SQLUser.MyStudents. This removes all rows and does reset the RowID counter. [1]

So for your case, instead of deleting rows based on LastUpdated < tMaxDate, you would use a full-table delete before loading the next file, such as either:

&SQL(DELETE FROM MC_Table_Data.Patient)

or

&SQL(TRUNCATE TABLE MC_Table_Data.Patient)

[1]

The retrieved example also shows that TRUNCATE TABLE is treated as a delete-type statement, and that its main behavioral difference from DELETE in the example is that it resets the RowID counter. [1]


Sources:

Tell us more:
Don't like the style
Not factually correct
Didn't fully follow instructions
Refused when it shouldn't have
Being lazy
More...
Submit
0 0