Compile function Copy_WO_WFR_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given WO_WFR record to the MSSQL database.
	
	History
	-------
	11/29/2016    KRF   Original Programmer
\*****************************************************************************/

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

$insert WO_WFR_EQUATES

CassNo = Field(Key, "*", 2)
Slot   = Field(Key, "*", 3)
If ( (CassNo NE '') and (Slot NE '') ) then

    // Parse record into a dimensioned array for speed
    Dim Rec(20)
    MatParse Record into Rec
                            
    // List of key names and their values
    Keys  = "WO_NO"  :@VM:SQL_Format(Field(Key, "*", 1), "INT"):@FM
    Keys := "CASS_NO":@VM:SQL_Format(Field(Key, "*", 2), "INT"):@FM
    Keys := "SLOT"   :@VM:SQL_Format(Field(Key, "*", 3), "INT")

    // List of data fields and their values
    DataFields  = "SHIP_FLAG"             :@VM:SQL_Format(Rec(WO_WFR_SHIP_FLAG$),  "BIT"):@FM
    DataFields := "GRADE"                 :@VM:SQL_Format(Rec(WO_WFR_GRADE$),      "STR"):@FM
    * DataFields := "SCRIBE"                :@VM:SQL_Format(Rec(WO_WFR_SCRIBE$),     "STR"):@FM
    DataFields := "GAN_RUN_ID"            :@VM:SQL_Format(Rec(WO_WFR_GAN_RUN_ID$), "STR"):@FM

    // Symbolics
    DataFields := "CARR_SLOT_ID"          :@VM:SQL_Format({CARR_SLOT_ID},           "STR"):@FM
    DataFields := "CARR_WFR_GRADE"        :@VM:SQL_Format({CARR_WFR_GRADE},         "STR"):@FM
    DataFields := "CURR_CASS_ID"          :@VM:SQL_Format({CURR_CASS_ID},           "STR"):@FM
    DataFields := "CURR_LOC_ID"           :@VM:SQL_Format({CURR_LOC_ID},            "STR"):@FM
    DataFields := "CURR_SLOT_ID"          :@VM:SQL_Format({CURR_SLOT_ID},           "STR"):@FM
    DataFields := "CURR_TOOL"             :@VM:SQL_Format({CURR_TOOL},              "STR"):@FM
    DataFields := "CUST_NAME"             :@VM:SQL_Format({CUST_NAME}[1,50],        "STR"):@FM
    DataFields := "CUST_NO"               :@VM:SQL_Format({CUST_NO},                "STR"):@FM
    DataFields := "ELAP_TM"               :@VM:SQL_Format({ELAP_TM},                "STR"):@FM
    DataFields := "EPI_STRUCTURE"         :@VM:SQL_Format({EPI_STRUCTURE},          "STR"):@FM
    DataFields := "GAN_WFR_ID"            :@VM:SQL_Format({GAN_WFR_ID},             "STR"):@FM
    DataFields := "POST_SLOT_DISP"        :@VM:SQL_Format({POST_SLOT_DISP},         "STR"):@FM
    DataFields := "PRE_SLOT_DISP"         :@VM:SQL_Format({PRE_SLOT_DISP},          "STR"):@FM
    DataFields := "RDS_NO"                :@VM:SQL_Format({RDS_NO},                 "STR"):@FM
    DataFields := "REACT_TYPE"            :@VM:SQL_Format({REACT_TYPE},             "STR"):@FM
    DataFields := "SCRIBE"                :@VM:SQL_Format({SCRIBE},                 "STR"):@FM
    DataFields := "GAN_GROWTH_UNLOAD_DTM" :@VM:SQL_Format({GAN_GROWTH_UNLOAD_DTM},  "DATETIME")

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

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

    // WO_WFR_LOGS
    If Ans EQ "" AND Rec(WO_WFR_LOC_DTM$) NE "" then
            
        // List of data fields and their values
        MvFields  = "LOC_DTM"  :@FM:SQL_Format(Rec(WO_WFR_LOC_DTM$),   "DATETIME"):@RM
        MvFields := "LOC_BY"   :@FM:SQL_Format(Rec(WO_WFR_LOC_BY$),    "STR"):@RM
        MvFields := "LOC_EVENT":@FM:SQL_Format(Rec(WO_WFR_LOC_EVENT$), "STR"):@RM
        MvFields := "SLOT_ID"  :@FM:SQL_Format(Rec(WO_WFR_SLOT_ID$),   "STR"):@RM
        MvFields := "RUN_LOC"  :@FM:SQL_Format(Rec(WO_WFR_RUN_LOC$),   "STR"):@RM
    *    MvFields := "NCR_NO"   :@FM:SQL_Format(Rec(WO_WFR_NCR_NO$),    "STR"):@RM
        MvFields := "TW_USE"   :@FM:SQL_Format(Rec(WO_WFR_TW_USE$),    "STR"):@RM
        MvFields := "DISP"     :@FM:SQL_Format({DISP},                 "STR")     
        
        // Write the data to the SQL database
        Ans = SQL_Write_MV(Connection, "WO_WFR_LOGS", Keys, MvFields)
        
    end
end

Return Ans
