Compile function Copy_CLEAN_INSP_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given CLEAN_INSP record to the MSSQL database.
	
	History
	-------
	05/24/2012    KRF   Original Programmer
\*****************************************************************************/

$insert CLEAN_INSP_EQUATES

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

// Parse record into a dimensioned array for speed
Dim Rec(72)
MatParse Record into Rec

// List of key names and their values
Keys = "CI_NO":@VM:SQL_Format(Key, "INT")

// List of data fields and their values
DataFields  = "WO_NO"                     :@VM:SQL_Format(Rec(CLEAN_INSP_WO_NO$),                      "INT"):@FM
DataFields := "WO_STEP"                   :@VM:SQL_Format(Rec(CLEAN_INSP_WO_STEP$),                    "INT"):@FM
DataFields := "CASS_NO"                   :@VM:SQL_Format(Rec(CLEAN_INSP_CASS_NO$),                    "INT"):@FM
DataFields := "STAGE"                     :@VM:SQL_Format(Rec(CLEAN_INSP_STAGE$),                      "STR"):@FM
DataFields := "RDS_NO"                    :@VM:SQL_Format(Rec(CLEAN_INSP_RDS_NO$),                     "INT"):@FM
DataFields := "SPEC_BRIGHTLIGHT"          :@VM:SQL_Format(Rec(CLEAN_INSP_SPEC_BRIGHTLIGHT$),           "BIT"):@FM
DataFields := "SPEC_MICROSCOPE"           :@VM:SQL_Format(Rec(CLEAN_INSP_SPEC_MICROSCOPE$),            "BIT"):@FM
DataFields := "SPEC_SURFSCAN"             :@VM:SQL_Format(Rec(CLEAN_INSP_SPEC_SURFSCAN_REQ$),          "BIT"):@FM
DataFields := "SPEC_CLEAN_SUBOXIDE"       :@VM:SQL_Format(Rec(CLEAN_INSP_SPEC_CLEAN_SUBOXIDE$),        "BIT"):@FM
DataFields := "SPEC_CLEAN_OXIDE_ANGSTROMS":@VM:SQL_Format(Rec(CLEAN_INSP_SPEC_CLEAN_OXIDE_ANGSTROMS$), "STR"):@FM
DataFields := "SPEC_CLEAN_AKRION_RECIPE"  :@VM:SQL_Format(Rec(CLEAN_INSP_SPEC_CLEAN_AKRION_RECIPE$),   "STR"):@FM
DataFields := "SPEC_PITS"                 :@VM:SQL_Format(Rec(CLEAN_INSP_SPEC_PITS$),                  "INT"):@FM
DataFields := "SPEC_MOUNDS"               :@VM:SQL_Format(Rec(CLEAN_INSP_SPEC_MOUNDS$),                "INT"):@FM
DataFields := "SPEC_BL_DEFECTS"           :@VM:SQL_Format(Rec(CLEAN_INSP_SPEC_BL_DEFECTS$),            "INT"):@FM
DataFields := "SPEC_SPOTS"                :@VM:SQL_Format(Rec(CLEAN_INSP_SPEC_SPOTS$),                 "INT"):@FM
DataFields := "SPEC_FOV"                  :@VM:SQL_Format(Rec(CLEAN_INSP_SPEC_FOV$),                   "INT"):@FM
DataFields := "SPEC_SCRATCHES"            :@VM:SQL_Format(Rec(CLEAN_INSP_SPEC_SCRATCHES$),             "INT"):@FM
DataFields := "SPEC_SCRATCH_LEN"          :@VM:SQL_Format(Rec(CLEAN_INSP_SPEC_SCRATCH_LEN$),           "INT"):@FM
DataFields := "SPEC_LPD"                  :@VM:SQL_Format(Rec(CLEAN_INSP_SPEC_LPD$),                   "INT"):@FM
DataFields := "SPEC_STACK_FAULTS"         :@VM:SQL_Format(Rec(CLEAN_INSP_SPEC_STACK_FAULTS$),          "INT"):@FM
DataFields := "SPEC_SPIKES"               :@VM:SQL_Format(Rec(CLEAN_INSP_SPEC_SPIKES$),                "INT"):@FM
DataFields := "SPEC_FWI_LWI"              :@VM:SQL_Format(Rec(CLEAN_INSP_SPEC_FWI_LWI$),               "STR"):@FM
DataFields := "COMMENTS"                  :@VM:SQL_Format(Rec(CLEAN_INSP_COMMENTS$),                   "STR"):@FM
DataFields := "SPC_DTM"                   :@VM:SQL_Format(Rec(CLEAN_INSP_SPC_DTM$),                    "DATETIME"):@FM
DataFields := "JCH_WAFER_CNT"             :@VM:SQL_Format(Rec(CLEAN_INSP_JCH_WAFER_CNT$),              "INT"):@FM
DataFields := "SHIFT"                     :@VM:SQL_Format(Rec(CLEAN_INSP_SHIFT$),                      "STR"):@FM

// Symbolics
CassIdSap = {CASS_ID_SAP}
DataFields := "CURR_STATUS"               :@VM:SQL_Format({CURR_STATUS},                               "STR"):@FM
DataFields := "POST_CLEAN_SS_SAMP_QTY"    :@VM:SQL_Format({POST_CLEAN_SS_SAMP_QTY},                    "INT"):@FM
DataFields := "REACT_NO"                  :@VM:SQL_Format({REACT_NO},                                  "STR"):@FM
DataFields := "WAFER_CNT"                 :@VM:SQL_Format({WAFER_CNT},                                 "INT"):@FM
DataFields := "WAFER_SIZE"                :@VM:SQL_Format({WAFER_SIZE},                                "STR"):@FM
DataFields := "CASS_ID_SAP"               :@VM:SQL_Format(CassIdSap,                                   "STR"):@FM
DataFields := "CURR_WFR_CNT"              :@VM:SQL_Format({CURR_WFR_CNT},                              "INT") 

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

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

// CLEAN_INSP_CLEAN_RESULTS
If Ans EQ "" AND Rec(CLEAN_INSP_CLEAN_TOOL$) NE "" then
    
    // List of data fields and their values
    MvFields  = "CLEAN_TOOL"   :@FM:SQL_Format(Rec(CLEAN_INSP_CLEAN_TOOL$),    "STR"):@RM
    MvFields := "CLEAN_BOAT_ID":@FM:SQL_Format(Rec(CLEAN_INSP_CLEAN_BOAT_ID$), "STR"):@RM
    MvFields := "CLEAN_SRD_NO" :@FM:SQL_Format(Rec(CLEAN_INSP_CLEAN_SRD_NO$),  "INT"):@RM
    MvFields := "CLEAN_SIG"    :@FM:SQL_Format(Rec(CLEAN_INSP_CLEAN_SIG$),     "STR"):@RM
    MvFields := "CLEAN_SIG_DTM":@FM:SQL_Format(Rec(CLEAN_INSP_CLEAN_SIG_DTM$), "DATETIME")
    
    RepeatFields = "CASS_ID_SAP":@VM:SQL_Format(CassIdSap, "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "CLEAN_INSP_CLEAN_RESULTS", Keys, MvFields, RepeatFields);
    
end

// CLEAN_INSP_INSP_RESULTS
If Ans EQ "" AND Rec(CLEAN_INSP_INSP_LPD_IN$) NE "" then
    
    // List of data fields and their values
    MvFields  = "INSP_LPD_IN"      :@FM:SQL_Format(Rec(CLEAN_INSP_INSP_LPD_IN$),       "INT"):@RM
    MvFields := "INSP_LPD_OUT"     :@FM:SQL_Format(Rec(CLEAN_INSP_INSP_LPD_OUT$),      "INT"):@RM
    MvFields := "INSP_SCRATCHES"   :@FM:SQL_Format(Rec(CLEAN_INSP_INSP_SCRATCHES$),    "INT"):@RM
    MvFields := "INSP_SCRATCH_LEN" :@FM:SQL_Format(Rec(CLEAN_INSP_INSP_SCRATCH_LEN$),  "INT"):@RM
    MvFields := "INSP_PITS"        :@FM:SQL_Format(Rec(CLEAN_INSP_INSP_PITS$),         "INT"):@RM
    MvFields := "INSP_MOUNDS"      :@FM:SQL_Format(Rec(CLEAN_INSP_INSP_MOUNDS$),       "INT"):@RM
    MvFields := "INSP_STACK_FAULTS":@FM:SQL_Format(Rec(CLEAN_INSP_INSP_STACK_FAULTS$), "INT"):@RM
    MvFields := "INSP_SPIKES"      :@FM:SQL_Format(Rec(CLEAN_INSP_INSP_SPIKES$),       "INT"):@RM
    MvFields := "INSP_SPOTS"       :@FM:SQL_Format(Rec(CLEAN_INSP_INSP_SPOTS$),        "INT"):@RM
    MvFields := "INSP_FOV"         :@FM:SQL_Format(Rec(CLEAN_INSP_INSP_FOV$),          "INT"):@RM
    MvFields := "INSP_BL_DEFECTS"  :@FM:SQL_Format(Rec(CLEAN_INSP_INSP_BL_DEFECTS$),   "INT"):@RM
    MvFields := "INSP_SIG"         :@FM:SQL_Format(Rec(CLEAN_INSP_INSP_SIG$),          "STR"):@RM
    MvFields := "INSP_SIG_DTM"     :@FM:SQL_Format(Rec(CLEAN_INSP_INSP_SIG_DTM$),      "DATETIME")
    
    RepeatFields = "CASS_ID_SAP":@VM:SQL_Format(CassIdSap, "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "CLEAN_INSP_INSP_RESULTS", Keys, MvFields, RepeatFields);
    
end

// CLEAN_INSP_SCAN_RESULTS
If Ans EQ "" AND Rec(CLEAN_INSP_SCAN_TOOL$) NE "" then
    
    // List of data fields and their values
    MvFields  = "SCAN_TOOL"             :@FM:SQL_Format(Rec(CLEAN_INSP_SCAN_TOOL$)<0, 1>,           "STR"):@RM
    MvFields := "SCAN_SUM_OF_DEF_MIN"   :@FM:SQL_Format(Rec(CLEAN_INSP_SCAN_SUM_OF_DEF_MIN$)<0, 1>, "INT"):@RM
    MvFields := "SCAN_SUM_OF_DEF_MAX"   :@FM:SQL_Format(Rec(CLEAN_INSP_SCAN_SUM_OF_DEF_MAX$)<0, 1>, "INT"):@RM
    MvFields := "SCAN_SUM_OF_DEF_AVG"   :@FM:SQL_Format(Rec(CLEAN_INSP_SCAN_SUM_OF_DEF_AVG$)<0, 1>, "DEC", 3):@RM
    MvFields := "SCAN_HAZE_AVG_MIN"     :@FM:SQL_Format(Rec(CLEAN_INSP_SCAN_HAZE_AVG_MIN$)<0, 1>,   "INT"):@RM
    MvFields := "SCAN_HAZE_AVG_MAX"     :@FM:SQL_Format(Rec(CLEAN_INSP_SCAN_HAZE_AVG_MAX$)<0, 1>,   "INT"):@RM
    MvFields := "SCAN_HAZE_AVG_AVG"     :@FM:SQL_Format(Rec(CLEAN_INSP_SCAN_HAZE_AVG_AVG$)<0, 1>,   "DEC", 3):@RM
    MvFields := "SCAN_SIG"              :@FM:SQL_Format(Rec(CLEAN_INSP_SCAN_SIG$)<0, 1>,            "STR"):@RM
    MvFields := "SPEC_SURFSCAN_RECIPE"  :@FM:SQL_Format(Rec(CLEAN_INSP_SPEC_SURFSCAN_RECIPE$),      "STR"):@RM
    MvFields := "SPEC_SS_SAMP_QTY"      :@FM:SQL_Format(Rec(CLEAN_INSP_SPEC_SS_SAMP_QTY$),          "INT"):@RM
    MvFields := "SPEC_SURF_HAZE"        :@FM:SQL_Format(Rec(CLEAN_INSP_SPEC_SURF_HAZE$),            "DEC", 2):@RM
    MvFields := "SPEC_SURF_DEFECTS"     :@FM:SQL_Format(Rec(CLEAN_INSP_SPEC_SURF_DEFECTS$),         "INT"):@RM
    MvFields := "SCAN_SIG_DTM"          :@FM:SQL_Format(Rec(CLEAN_INSP_SCAN_SIG_DTM$)<0, 1>,        "DATETIME")
    
    RepeatFields = "CASS_ID_SAP":@VM:SQL_Format(CassIdSap, "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "CLEAN_INSP_SCAN_RESULTS", Keys, MvFields, RepeatFields);
    
end

// CLEAN_INSP_CLEAN_VER_SIG
If Ans EQ "" AND Rec(CLEAN_INSP_CLEAN_VER_SIG$) NE "" then
    
    // List of data fields and their values
    MvFields  = "CLEAN_VER_SIG"    :@FM:SQL_Format(Rec(CLEAN_INSP_CLEAN_VER_SIG$),     "STR"):@RM
    MvFields := "CLEAN_VER_SIG_DTM":@FM:SQL_Format(Rec(CLEAN_INSP_CLEAN_VER_SIG_DTM$), "DATETIME")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "CLEAN_INSP_CLEAN_VER_SIG", Keys, MvFields);
    
end

// CLEAN_INSP_INSP_VER_SIG
If Ans EQ "" AND Rec(CLEAN_INSP_INSP_VER_SIG$) NE "" then
    
    // List of data fields and their values
    MvFields  = "INSP_VER_SIG"    :@FM:SQL_Format(Rec(CLEAN_INSP_INSP_VER_SIG$),     "STR"):@RM
    MvFields := "INSP_VER_SIG_DTM":@FM:SQL_Format(Rec(CLEAN_INSP_INSP_VER_SIG_DTM$), "DATETIME")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "CLEAN_INSP_INSP_VER_SIG", Keys, MvFields);
    
end

// CLEAN_INSP_SCAN_VER_SIG
If Ans EQ "" AND Rec(CLEAN_INSP_SCAN_VER_SIG$) NE "" then
    
    // List of data fields and their values
    MvFields  = "SCAN_VER_SIG"    :@FM:SQL_Format(Rec(CLEAN_INSP_SCAN_VER_SIG$),     "STR"):@RM
    MvFields := "SCAN_VER_SIG_DTM":@FM:SQL_Format(Rec(CLEAN_INSP_SCAN_VER_SIG_DTM$), "DATETIME")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "CLEAN_INSP_SCAN_VER_SIG", Keys, MvFields);
    
end

// CLEAN_INSP_SPEC_CLEAN_TOOL
If Ans EQ "" AND Rec(CLEAN_INSP_SPEC_CLEAN_TOOL$) NE "" then
    
    // List of data fields and their values
    MvFields = "SPEC_CLEAN_TOOL":@FM:SQL_Format(Rec(CLEAN_INSP_SPEC_CLEAN_TOOL$), "STR")
    RepeatFields = "CASS_ID_SAP":@VM:SQL_Format(CassIdSap, "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "CLEAN_INSP_SPEC_CLEAN_TOOL", Keys, MvFields, RepeatFields);
    
end

Return Ans
