Compile function Copy_RDS_TEST_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given RDS_TEST record to the MSSQL database.
	
	History
	-------
	06/24/2010    KRF   Original Programmer
\*****************************************************************************/

$insert RDS_TEST_EQUATES

Declare function SQL_Write, SQL_Write_MV, SQL_Format, Obj_Rds_Test
Ans = ""

// Parse record into a dimensioned array for speed
Dim Rec(144)
MatParse Record into Rec
					    
// List of key names and their values
Keys = "MET_NO":@VM:SQL_Format(Key, "INT")

// List of data fields and their values
DataFields  = "RDS_NO"                :@VM:SQL_Format(Rec(RDS_TEST_RDS_NO$),                 "INT"):@FM
DataFields := "LS_ID"                 :@VM:SQL_Format(Rec(RDS_TEST_LS_ID$),                  "STR"):@FM
DataFields := "ZONE"                  :@VM:SQL_Format(Rec(RDS_TEST_ZONE$),                   "STR"):@FM
DataFields := "SPEC_DOPANT"           :@VM:SQL_Format(Rec(RDS_TEST_SPEC_DOPANT$),            "STR"):@FM
DataFields := "SPEC_RECIPE"           :@VM:SQL_Format(Rec(RDS_TEST_SPEC_RECIPE$),            "STR"):@FM
DataFields := "SPEC_RECIPE_NAME"      :@VM:SQL_Format(Rec(RDS_TEST_SPEC_RECIPE_NAME$),       "STR"):@FM
DataFields := "SPEC_THICK_MIN"        :@VM:SQL_Format(Rec(RDS_TEST_SPEC_THICK_MIN$),         "DEC", "2"):@FM
DataFields := "SPEC_THICK_TARGET"     :@VM:SQL_Format(Rec(RDS_TEST_SPEC_THICK_TARGET$),      "DEC", "2"):@FM
DataFields := "SPEC_THICK_MAX"        :@VM:SQL_Format(Rec(RDS_TEST_SPEC_THICK_MAX$),         "DEC", "2"):@FM
DataFields := "SPEC_THICK_UNITS"      :@VM:SQL_Format(Rec(RDS_TEST_SPEC_THICK_UNITS$),       "STR"):@FM
DataFields := "SPEC_THICK_MTOOL"      :@VM:SQL_Format(Rec(RDS_TEST_SPEC_THICK_MTOOL$),       "STR"):@FM
DataFields := "SPEC_THICK_MTYPE"      :@VM:SQL_Format(Rec(RDS_TEST_SPEC_THICK_MTYPE$),       "STR"):@FM
DataFields := "SPEC_THICK_MRECIPE"    :@VM:SQL_Format(Rec(RDS_TEST_SPEC_THICK_MRECIPE$),     "STR"):@FM
DataFields := "SPEC_THICK_MFREQ"      :@VM:SQL_Format(Rec(RDS_TEST_SPEC_THICK_MFREQ$),       "INT"):@FM
DataFields := "SPEC_THICK_MPROVEIN"   :@VM:SQL_Format(Rec(RDS_TEST_SPEC_THICK_MPROVEIN$),    "STR"):@FM
DataFields := "SPEC_THICK_MFIRST"     :@VM:SQL_Format(Rec(RDS_TEST_SPEC_THICK_MFIRST$),      "BIT"):@FM
DataFields := "SPEC_THICK_MLAST"      :@VM:SQL_Format(Rec(RDS_TEST_SPEC_THICK_MLAST$),       "BIT"):@FM
DataFields := "SPEC_THICK_MSPC"       :@VM:SQL_Format(Rec(RDS_TEST_SPEC_THICK_MSPC$),        "BIT"):@FM
DataFields := "SPEC_THICK_MOVERGROW"  :@VM:SQL_Format(Rec(RDS_TEST_SPEC_THICK_MOVERGROW$),   "BIT"):@FM
DataFields := "SPEC_RES_MIN"          :@VM:SQL_Format(Rec(RDS_TEST_SPEC_RES_MIN$),           "DEC", "3"):@FM
DataFields := "SPEC_RES_TARGET"       :@VM:SQL_Format(Rec(RDS_TEST_SPEC_RES_TARGET$),        "DEC", "3"):@FM
DataFields := "SPEC_RES_MAX"          :@VM:SQL_Format(Rec(RDS_TEST_SPEC_RES_MAX$),           "DEC", "3"):@FM
DataFields := "SPEC_RES_UNITS"        :@VM:SQL_Format(Rec(RDS_TEST_SPEC_RES_UNITS$),         "STR"):@FM
DataFields := "SPEC_RES_MTOOL"        :@VM:SQL_Format(Rec(RDS_TEST_SPEC_RES_MTOOL$),         "STR"):@FM
DataFields := "SPEC_RES_MTYPE"        :@VM:SQL_Format(Rec(RDS_TEST_SPEC_RES_MTYPE$),         "STR"):@FM
DataFields := "SPEC_RES_MRECIPE"      :@VM:SQL_Format(Rec(RDS_TEST_SPEC_RES_MRECIPE$),       "STR"):@FM
DataFields := "SPEC_RES_MFREQ"        :@VM:SQL_Format(Rec(RDS_TEST_SPEC_RES_MFREQ$),         "INT"):@FM
DataFields := "SPEC_RES_MPROVEIN"     :@VM:SQL_Format(Rec(RDS_TEST_SPEC_RES_MPROVEIN$),      "STR"):@FM
DataFields := "SPEC_RES_MFIRST"       :@VM:SQL_Format(Rec(RDS_TEST_SPEC_RES_MFIRST$),        "BIT"):@FM
DataFields := "SPEC_RES_MLAST"        :@VM:SQL_Format(Rec(RDS_TEST_SPEC_RES_MLAST$),         "BIT"):@FM
DataFields := "SPEC_RES_MSPC"         :@VM:SQL_Format(Rec(RDS_TEST_SPEC_RES_MSPC$),          "BIT"):@FM
DataFields := "SPEC_RES_MOVERGROW"    :@VM:SQL_Format(Rec(RDS_TEST_SPEC_RES_MOVERGROW$),     "BIT"):@FM
DataFields := "SPEC_CON_UNITS"        :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CON_UNITS$),         "STR"):@FM
DataFields := "SPEC_CON_MTOOL"        :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CON_MTOOL$),         "STR"):@FM
DataFields := "SPEC_CON_MTYPE"        :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CON_MTYPE$),         "STR"):@FM
DataFields := "SPEC_CON_MRECIPE"      :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CON_MRECIPE$),       "STR"):@FM
DataFields := "SPEC_CON_MFREQ"        :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CON_MFREQ$),         "INT"):@FM
DataFields := "SPEC_CON_MPROVEIN"     :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CON_MPROVEIN$),      "STR"):@FM
DataFields := "SPEC_CON_MFIRST"       :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CON_MFIRST$),        "BIT"):@FM
DataFields := "SPEC_CON_MLAST"        :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CON_MLAST$),         "BIT"):@FM
DataFields := "SPEC_CON_MSPC"         :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CON_MSPC$),          "BIT"):@FM
DataFields := "SPEC_CON_MOVERGROW"    :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CON_MOVERGROW$),     "BIT"):@FM
DataFields := "SPEC_STRESS_MIN"       :@VM:SQL_Format(Rec(RDS_TEST_SPEC_STRESS_MIN$),        "STR"):@FM
DataFields := "SPEC_STRESS_TARGET"    :@VM:SQL_Format(Rec(RDS_TEST_SPEC_STRESS_TARGET$),     "STR"):@FM
DataFields := "SPEC_STRESS_MAX"       :@VM:SQL_Format(Rec(RDS_TEST_SPEC_STRESS_MAX$),        "STR"):@FM
DataFields := "SPEC_STRESS_UNITS"     :@VM:SQL_Format(Rec(RDS_TEST_SPEC_STRESS_UNITS$),      "STR"):@FM
DataFields := "SPEC_STRESS_MTOOL"     :@VM:SQL_Format(Rec(RDS_TEST_SPEC_STRESS_MTOOL$),      "STR"):@FM
DataFields := "SPEC_STRESS_MTYPE"     :@VM:SQL_Format(Rec(RDS_TEST_SPEC_STRESS_MTYPE$),      "STR"):@FM
DataFields := "SPEC_STRESS_MRECIPE"   :@VM:SQL_Format(Rec(RDS_TEST_SPEC_STRESS_MRECIPE$),    "STR"):@FM
DataFields := "SPEC_STRESS_MFREQ"     :@VM:SQL_Format(Rec(RDS_TEST_SPEC_STRESS_MFREQ$),      "INT"):@FM
DataFields := "SPEC_STRESS_MPROVEIN"  :@VM:SQL_Format(Rec(RDS_TEST_SPEC_STRESS_MPROVEIN$),   "STR"):@FM
DataFields := "SPEC_STRESS_MFIRST"    :@VM:SQL_Format(Rec(RDS_TEST_SPEC_STRESS_MFIRST$),     "BIT"):@FM
DataFields := "SPEC_STRESS_MLAST"     :@VM:SQL_Format(Rec(RDS_TEST_SPEC_STRESS_MLAST$),      "BIT"):@FM
DataFields := "SPEC_STRESS_MSPC"      :@VM:SQL_Format(Rec(RDS_TEST_SPEC_STRESS_MSPC$),       "BIT"):@FM
DataFields := "SPEC_STRESS_MOVERGROW" :@VM:SQL_Format(Rec(RDS_TEST_SPEC_STRESS_MOVERGROW$),  "BIT"):@FM
DataFields := "THICK_OVERGROW_AVG"    :@VM:SQL_Format(Rec(RDS_TEST_THICK_OVERGROW_AVG$),     "DEC", "2"):@FM
DataFields := "HGCV_MEAN"             :@VM:SQL_Format(Rec(RDS_TEST_HGCV_MEAN$),              "DEC", "6"):@FM
DataFields := "HGCV_STDV"             :@VM:SQL_Format(Rec(RDS_TEST_HGCV_STDV$),              "DEC", "6"):@FM
DataFields := "THICK_AVG"             :@VM:SQL_Format(Rec(RDS_TEST_THICK_AVG$),              "DEC", "2"):@FM
DataFields := "THICK_STDV"            :@VM:SQL_Format(Rec(RDS_TEST_THICK_STDV$),             "DEC", "4"):@FM
DataFields := "THICK_UNIF"            :@VM:SQL_Format(Rec(RDS_TEST_THICK_UNIF$),             "DEC", "2"):@FM
DataFields := "THICK_MIN"             :@VM:SQL_Format(Rec(RDS_TEST_THICK_MIN$),              "DEC", "2"):@FM
DataFields := "THICK_MAX"             :@VM:SQL_Format(Rec(RDS_TEST_THICK_MAX$),              "DEC", "2"):@FM
DataFields := "SHEETRHO_AVG"          :@VM:SQL_Format(Rec(RDS_TEST_SHEETRHO_AVG$),           "DEC", "3"):@FM
DataFields := "SHEETRHO_STDV"         :@VM:SQL_Format(Rec(RDS_TEST_SHEETRHO_STDV$),          "DEC", "4"):@FM
DataFields := "SHEETRHO_UNIF"         :@VM:SQL_Format(Rec(RDS_TEST_SHEETRHO_UNIF$),          "DEC", "2"):@FM
DataFields := "SHEETRHO_MIN"          :@VM:SQL_Format(Rec(RDS_TEST_SHEETRHO_MIN$),           "DEC", "3"):@FM
DataFields := "SHEETRHO_MAX"          :@VM:SQL_Format(Rec(RDS_TEST_SHEETRHO_MAX$),           "DEC", "3"):@FM
DataFields := "RES_AVG"               :@VM:SQL_Format(Rec(RDS_TEST_RES_AVG$),                "DEC", "4"):@FM
DataFields := "RES_STDV"              :@VM:SQL_Format(Rec(RDS_TEST_RES_STDV$),               "DEC", "4"):@FM
DataFields := "RES_UNIF"              :@VM:SQL_Format(Rec(RDS_TEST_RES_UNIF$),               "DEC", "2"):@FM
DataFields := "RES_MIN"               :@VM:SQL_Format(Rec(RDS_TEST_RES_MIN$),                "DEC", "4"):@FM
DataFields := "RES_MAX"               :@VM:SQL_Format(Rec(RDS_TEST_RES_MAX$),                "DEC", "4"):@FM
DataFields := "SPEC_TRANS"            :@VM:SQL_Format(Rec(RDS_TEST_SPEC_TRANS$),             "STR"):@FM
DataFields := "SPEC_TRANS_MEASUREMENT":@VM:SQL_Format(Rec(RDS_TEST_SPEC_TRANS_MEASUREMENT$), "STR"):@FM
DataFields := "WAFER_SIZE"            :@VM:SQL_Format(Rec(RDS_TEST_WAFER_SIZE$),             "STR"):@FM
DataFields := "SUB_ORIENTATION"       :@VM:SQL_Format(Rec(RDS_TEST_SUB_ORIENTATION$)<1, 1>,  "STR"):@FM
DataFields := "ASET_RESULTS"          :@VM:SQL_Format(Rec(RDS_TEST_ASET_RESULTS$),           "DEC", "1"):@FM
DataFields := "REACTOR_TYPE"          :@VM:SQL_Format(Rec(RDS_TEST_REACTOR_TYPE$),           "STR"):@FM
DataFields := "TEST_POINT_MAP"        :@VM:SQL_Format(Rec(RDS_TEST_TEST_POINT_MAP$),         "STR"):@FM
DataFields := "HGCV1_RES_AVG"         :@VM:SQL_Format(Rec(RDS_TEST_HGCV1_RES_AVG$),          "DEC", "3"):@FM
DataFields := "HGCV1_RES_STDV"        :@VM:SQL_Format(Rec(RDS_TEST_HGCV1_RES_STDV$),         "DEC", "3"):@FM
DataFields := "HGCV1_RES_UNIF"        :@VM:SQL_Format(Rec(RDS_TEST_HGCV1_RES_UNIF$),         "DEC", "2"):@FM
DataFields := "HGCV1_RES_MIN"         :@VM:SQL_Format(Rec(RDS_TEST_HGCV1_RES_MIN$),          "DEC", "3"):@FM
DataFields := "HGCV1_RES_MAX"         :@VM:SQL_Format(Rec(RDS_TEST_HGCV1_RES_MAX$),          "DEC", "3"):@FM
DataFields := "SPC_DTM"               :@VM:SQL_Format(Rec(RDS_TEST_SPC_DTM$),                "DATETIME"):@FM
DataFields := "SPEC_CRES_MIN"         :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CRES_MIN$),          "STR"):@FM
DataFields := "SPEC_CRES_TARGET"      :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CRES_TARGET$),       "STR"):@FM
DataFields := "SPEC_CRES_MAX"         :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CRES_MAX$),          "STR"):@FM
DataFields := "SPEC_CRES_UNITS"       :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CRES_UNITS$),        "STR"):@FM
DataFields := "SPEC_CRES_MTOOL"       :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CRES_MTOOL$),        "STR"):@FM
DataFields := "SPEC_CRES_MTYPE"       :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CRES_MTYPE$),        "STR"):@FM
DataFields := "SPEC_CRES_MRECIPE"     :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CRES_MRECIPE$),      "STR"):@FM
DataFields := "SPEC_CRES_MFREQ"       :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CRES_MFREQ$),        "INT"):@FM
DataFields := "SPEC_CRES_MPROVEIN"    :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CRES_MPROVEIN$),     "STR"):@FM
DataFields := "SPEC_CRES_MFIRST"      :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CRES_MFIRST$),       "BIT"):@FM
DataFields := "SPEC_CRES_MLAST"       :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CRES_MLAST$),        "BIT"):@FM
DataFields := "SPEC_CRES_MSPC"        :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CRES_MSPC$),         "BIT"):@FM
DataFields := "SPEC_CRES_MOVERGROW"   :@VM:SQL_Format(Rec(RDS_TEST_SPEC_CRES_MOVERGROW$),    "BIT"):@FM

// Symbolics
DataFields := "CASS_NO"     :@VM:SQL_Format({CASS_NO},      "INT"):@FM
DataFields := "CUST_NO"     :@VM:SQL_Format({CUST_NO},      "STR"):@FM
DataFields := "DEP_TIME"    :@VM:SQL_Format({DEP_TIME},     "STR"):@FM
DataFields := "GROWTH_RATE" :@VM:SQL_Format({GROWTH_RATE},  "DEC", 2):@FM
DataFields := "MET_COMPLETE":@VM:SQL_Format({MET_COMPLETE}, "BIT"):@FM
DataFields := "PART_NO"     :@VM:SQL_Format({PART_NO},      "STR"):@FM
DataFields := "PS_NO"       :@VM:SQL_Format({PS_NO},        "STR"):@FM
DataFields := "RDS_LAYER"   :@VM:SQL_Format({RDS_LAYER},    "STR"):@FM
DataFields := "REACTOR"     :@VM:SQL_Format({REACTOR},      "STR"):@FM
DataFields := "SPEC_TYPE"   :@VM:SQL_Format({SPEC_TYPE},    "STR"):@FM
DataFields := "WAFER_TYPE"  :@VM:SQL_Format({WAFER_TYPE},   "STR"):@FM
DataFields := "WO_NO"       :@VM:SQL_Format({WO_NO},        "INT"):@FM

// The reads are now added within the RDS_TEST table itself, so we need to loop though and expand them
If Len(Rec(RDS_TEST_TEST_POINT_MAP$)) then
    ExportReadings = Obj_Rds_Test("ExpReadings", Key:@RM:Record:@RM:1)
    TestPoints    = ExportReadings[1, @FM]
    ReadThicks    = ExportReadings[Col2() + 1, @FM]
    ReadSheetRHOs = ExportReadings[Col2() + 1, @FM]
    ReadHGCVs     = ExportReadings[Col2() + 1, @FM]
    ReadResists   = ExportReadings[Col2() + 1, @FM]
    If Ans EQ "" AND (Len(TestPoints) OR Len(ReadThicks) OR Len(ReadSheetRHOs) OR Len(ReadHGCVs) OR Len(ReadResists)) then
        
        NumReadings = Count(TestPoints, @VM) + 1
        
*        If Key EQ 470677 then debug
        
        If TestPoints<1, 1>[3, 2] _EQC "mm" OR TestPoints<1, 2>[3, 2] _EQC "mm" then
            LastValue = 0
            Prefix = "L"
            For iReading = 1 to NumReadings
                TestPoint    = TestPoints<1, iReading>
                If Len(TestPoint) then
                    ReadThick    = ReadThicks<1, iReading>
                    ReadSheetRHO = ReadSheetRHOs<1, iReading>
                    ReadHGCV     = ReadHGCVs<1, iReading>
                    ReadResist   = ReadResists<1, iReading>
                    If TestPoint[1, 1] _EQC "C" then
                        Prefix = "R"
                        DataFields := "C_THICK"    :@VM:ReadThick   :@FM
                        DataFields := "C_SHEET_RHO":@VM:ReadSheetRHO:@FM
                        DataFields := "C_HGCV"     :@VM:ReadHGCV    :@FM
                        DataFields := "C_RES"      :@VM:ReadResist  :@FM
                    end else
                        If LastValue EQ TestPoint[1, 2] then Prefix = "R"
                        DataFields := Prefix:TestPoint[1, 2]:"_THICK"    :@VM:ReadThick   :@FM
                        DataFields := Prefix:TestPoint[1, 2]:"_SHEET_RHO":@VM:ReadSheetRHO:@FM
                        DataFields := Prefix:TestPoint[1, 2]:"_HGCV"     :@VM:ReadHGCV    :@FM
                        DataFields := Prefix:TestPoint[1, 2]:"_RES"      :@VM:ReadResist  :@FM
                        LastValue = TestPoint[1, 2]
                    end
                end
            Next iReading
        end else
            For iReading = 1 to NumReadings
                TestPoint    = TestPoints<1, iReading>
                If Len(TestPoint) then
                    ReadThick    = ReadThicks<1, iReading>
                    ReadSheetRHO = ReadSheetRHOs<1, iReading>
                    ReadHGCV     = ReadHGCVs<1, iReading>
                    ReadResist   = ReadResists<1, iReading>
                    DataFields := TestPoint:"_THICK"    :@VM:ReadThick   :@FM
                    DataFields := TestPoint:"_SHEET_RHO":@VM:ReadSheetRHO:@FM
                    DataFields := TestPoint:"_HGCV"     :@VM:ReadHGCV    :@FM
                    DataFields := TestPoint:"_RES"      :@VM:ReadResist  :@FM
                end
            Next iReading
        end
    
    end
end

// Remove the intentional trailing @FM
DataFields[-1, 1] = ""

// Write the data to the SQL database
Ans = SQL_Write(Connection, "RDS_TEST", Keys, DataFields)

//-------------------------------------------------------------------------------------------------
// Multi-valued Fields


// RDS_TEST_SPEC_CON
If Ans EQ "" AND (Rec(33) OR Rec(34) OR Rec(35)) then
    
    // List of data fields and their values
    MvFields  = "SPEC_CON_MIN":@FM:SQL_Format(Rec(33), "STR", 1):@RM
    MvFields := "SPEC_CON_TARGET":@FM:SQL_Format(Rec(34), "STR", 1):@RM
    MvFields := "SPEC_CON_MAX":@FM:SQL_Format(Rec(35), "STR", 1)
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "RDS_TEST_SPEC_CON", Keys, MvFields);
    
end

// RDS_TEST_MODIFY
If Ans EQ "" AND (Rec(100) OR Rec(101)) then
    
    // List of data fields and their values
    MvFields  = "MODIFY_USER":@FM:SQL_Format(Rec(100), "STR"):@RM
    MvFields := "MODIFY_DTM":@FM:SQL_Format(Rec(101), "DATETIME")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "RDS_TEST_MODIFY", Keys, MvFields);
    
end

// RDS_TEST_SRP_PROFILE_PATH
If Ans EQ "" AND (Rec(66)) then
    
    // List of data fields and their values
    MvFields  = "SRP_PROFILE_PATH":@FM:SQL_Format(Rec(66), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "RDS_TEST_SRP_PROFILE_PATH", Keys, MvFields);
    
end

// RDS_TEST_TW
If Ans EQ "" AND (Rec(70) OR Rec(115) OR Rec(72)) then
    
    // List of data fields and their values
    MvFields  = "TW_TYPE":@FM:SQL_Format(Rec(70), "STR"):@RM
    MvFields := "TW_CNT":@FM:SQL_Format(Rec(71), "INT"):@RM
    MvFields := "TW_CODE":@FM:SQL_Format(Rec(72), "INT"):@RM
    MvFields := "TW_CON":@FM:SQL_Format(Rec(73), "STR"):@RM
    MvFields := "TW_RES":@FM:SQL_Format(Rec(74), "DEC", 3):@RM
    MvFields := "TW_RHO":@FM:SQL_Format(Rec(75), "INT"):@RM
    MvFields := "TW_STRESS":@FM:SQL_Format(Rec(76), "STR"):@RM
    MvFields := "TW_THICK":@FM:SQL_Format(Rec(77), "DEC", 2):@RM
    MvFields := "TW_TOOL":@FM:SQL_Format(Rec(78), "STR"):@RM
    MvFields := "TW_TRANS":@FM:SQL_Format(Rec(79), "DEC", 2):@RM
    MvFields := "TW_SIG":@FM:SQL_Format(Rec(111), "STR"):@RM
    MvFields := "TW_SIG_DTM":@FM:SQL_Format(Rec(112), "DATETIME"):@RM
    MvFields := "TW_HRS_SINCE_PERIOD":@FM:SQL_Format(Rec(113), "DEC", 2):@RM
    MvFields := "TW_HRS_ESC":@FM:SQL_Format(Rec(114), "DEC", 2):@RM
    MvFields := "TW_WAFER_ID":@FM:SQL_Format(Rec(115), "STR", 1)
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "RDS_TEST_TW", Keys, MvFields);
    
end

* // RDS_TEST_READ
* ExportReadings = Obj_Rds_Test("ExpReadings", Key:@RM:Record:@RM:1)
* TestPoints   = ExportReadings[1, @FM]
* ReadThicks   = ExportReadings[Col2() + 1, @FM]
* ReadSheetRHO = ExportReadings[Col2() + 1, @FM]
* ReadHGCV1Res = ExportReadings[Col2() + 1, @FM]
* ReadRes      = ExportReadings[Col2() + 1, @FM]
* If Ans EQ "" AND (Len(TestPoints) OR Len(ReadThicks) OR Len(ReadSheetRHO) OR Len(ReadHGCV1Res) OR Len(ReadRes)) then
*    
*    // List of data fields and their values
*    MvFields  = "TEST_POINT"    :@FM:SQL_Format(TestPoints, "STR"):@RM
*    MvFields := "READ_THICK"    :@FM:ReadThicks:@RM
*    MvFields := "READ_SHEET_RHO":@FM:ReadSheetRHO:@RM
*    MvFields := "READ_HGCV1_RES":@FM:ReadHGCV1Res:@RM
*    MvFields := "READ_RES"      :@FM:ReadRes
* 
*    // Write the data to the SQL database
*    Ans = SQL_Write_MV(Connection, "RDS_TEST_READ", Keys, MvFields);
* end

// RDS_TEST_STRESS
If Ans EQ "" AND (Rec(63) OR Rec(64) OR Rec(65)) then
    
    // List of data fields and their values
    MvFields  = "STRESS_BORON":@FM:SQL_Format(Rec(63), "DEC", 2):@RM
    MvFields := "STRESS_GEH4":@FM:SQL_Format(Rec(64), "DEC", 2):@RM
    MvFields := "STRESS_MPS":@FM:SQL_Format(Rec(65), "DEC", 2)

    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "RDS_TEST_STRESS", Keys, MvFields);
    
end

// RDS_TEST_TW_USE
If Ans EQ "" AND Rec(RDS_TEST_TW_USE_ID$) then
    
    // List of data fields and their values
    MvFields  = "TW_USE_ID"   :@FM:SQL_Format(Rec(RDS_TEST_TW_USE_ID$), "STR"):@RM
    MvFields := "TWU_CODE"    :@FM:SQL_Format({TWU_CODE},               "STR"):@RM
    MvFields := "TWU_DESC"    :@FM:SQL_Format({TWU_DESC},               "STR"):@RM
    MvFields := "TWU_QTY"     :@FM:SQL_Format({TWU_QTY},                "INT"):@RM
    MvFields := "TWU_TOOL"    :@FM:SQL_Format({TWU_TOOL},               "STR"):@RM
    MvFields := "TWU_TYPE"    :@FM:SQL_Format({TWU_TYPE},               "STR"):@RM
    MvFields := "TWU_USE_DESC":@FM:SQL_Format({TWU_USE_DESC},           "STR")
    // TWU_WAFER_ID itself is multi-value and would need to be normalized
    // into a child table of the RDS_TEST_TW_USE table. 
*    MvFields := "TWU_WAFER_ID":@FM:SQL_Format({TWU_WAFER_ID},           "STR")

    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "RDS_TEST_TW_USE", Keys, MvFields);
    
end

Return Ans
