Compile function Copy_REACT_MODE_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given REACT_MODE record to the MSSQL database.
	
	History
	-------
	08/14/2012    KRF   Original Programmer
\*****************************************************************************/

$insert REACT_MODE_EQUATES

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

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

// List of key names and their values
Keys  = "REACT_NO" :@VM:SQL_Format(Field(Key, "*", 1), "INT"):@FM
Keys := "START_DTM":@VM:SQL_Format(Field(Key, "*", 2), "DATETIME")

// List of data fields and their values
DataFields  = "START_USER"       :@VM:SQL_Format(Rec(REACT_MODE_START_USER$),  "STR"):@FM
DataFields := "START_NOTE"       :@VM:SQL_Format(Rec(REACT_MODE_START_NOTE$),  "STR"):@FM
DataFields := "MODE"             :@VM:SQL_Format(Rec(REACT_MODE_MODE$),        "STR"):@FM
DataFields := "STOP_DTM"         :@VM:SQL_Format(Rec(REACT_MODE_STOP_DTM$),    "DATETIME"):@FM
DataFields := "STOP_USER"        :@VM:SQL_Format(Rec(REACT_MODE_STOP_USER$),   "STR"):@FM
DataFields := "STOP_NOTE"        :@VM:SQL_Format(Rec(REACT_MODE_STOP_NOTE$),   "STR"):@FM
DataFields := "START_RL_ID"      :@VM:SQL_Format(Rec(REACT_MODE_START_RL_ID$), "INT"):@FM

// Symbolics
DataFields := "ELAP_HRS"         :@VM:SQL_Format({ELAP_HRS},                   "DEC", 2):@FM
DataFields := "REACT_ACTIVE_MODE":@VM:SQL_Format({REACT_ACTIVE_MODE},          "STR"):@FM
DataFields := "START_DT"         :@VM:SQL_Format({START_DT},                   "DATE"):@FM
DataFields := "START_NOTES"      :@VM:SQL_Format({START_NOTES},                "STR"):@FM
DataFields := "STOP_DT"          :@VM:SQL_Format({STOP_DT},                    "DATE"):@FM
DataFields := "START_NOTE_TEXT"  :@VM:SQL_Format({START_NOTE_TEXT},            "STR"):@FM
DataFields := "STOP_NOTE_TEXT"   :@VM:SQL_Format({STOP_NOTE_TEXT},             "STR")

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

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

// REACT_MODE_NON_PROD_DT
NonProdDt = {NON_PROD_DT}
If Ans EQ "" AND NonProdDt NE "" then
    
    // List of data fields and their values
    MvFields = "NON_PROD_DT":@FM:SQL_Format(NonProdDt, "DATE")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "REACT_MODE_NON_PROD_DT", Keys, MvFields);
    
end

// REACT_MODE_SERV_INFO
ProbCatId   = {PROB_CAT_ID}
ProbCatDesc = {PROB_CAT_DESC}
ServId      = {SERV_ID}
ServDesc    = {SERV_DESC}
If Ans EQ "" AND (ProbCatId NE "" OR ProbCatDesc NE "" OR ServId NE "" OR ServDesc NE "") then
    
    // List of data fields and their values
    MvFields  = "PROB_CAT_ID"  :@FM:SQL_Format(ProbCatId,   "STR"):@RM
    MvFields := "PROB_CAT_DESC":@FM:SQL_Format(ProbCatDesc, "STR"):@RM
    MvFields := "SERV_ID"      :@FM:SQL_Format(ServId,      "STR"):@RM
    MvFields := "SERV_DESC"    :@FM:SQL_Format(ServDesc,    "STR"):@RM
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "REACT_MODE_SERV_INFO", Keys, MvFields);
    
end

Return Ans
