Compile function Copy_MFC_Record_To_SQL(Connection, Key, Record)

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

$insert MFC_EQUATES

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

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

// List of data fields and their values
DataFields  = "ASM_PN"          :@VM:SQL_Format(Rec(MFC_ASM_PN$),           "STR"):@FM
DataFields := "MFR"             :@VM:SQL_Format(Rec(MFC_MFR$),              "STR"):@FM
DataFields := "FLOW"            :@VM:SQL_Format(Rec(MFC_FLOW$),             "STR"):@FM
DataFields := "INLET_PRESS"     :@VM:SQL_Format(Rec(MFC_INLET_PRESS$),      "INT"):@FM
DataFields := "OUTLET_PRESS"    :@VM:SQL_Format(Rec(MFC_OUTLET_PRESS$),     "STR"):@FM
DataFields := "CURR_MFC_LOC"    :@VM:SQL_Format(Rec(MFC_CURR_MFC_LOC$),     "STR"):@FM
DataFields := "CURR_INSTALL_DTM":@VM:SQL_Format(Rec(MFC_CURR_INSTALL_DTM$), "DATETIME"):@FM
DataFields := "CURR_TECH_SIG"   :@VM:SQL_Format(Rec(MFC_CURR_TECH_SIG$),    "STR"):@FM
DataFields := "OTHER_LOC"       :@VM:SQL_Format(Rec(MFC_OTHER_LOC$),        "STR"):@FM
DataFields := "COMMENTS"        :@VM:SQL_Format(Rec(MFC_COMMENTS$),         "STR"):@FM
DataFields := "DECOM_DTM"       :@VM:SQL_Format(Rec(MFC_DECOM_DTM$),        "DATETIME"):@FM
DataFields := "DECOM_BY"        :@VM:SQL_Format(Rec(MFC_DECOM_BY$),         "STR"):@FM
DataFields := "DECOM_REASON"    :@VM:SQL_Format(Rec(MFC_DECOM_REASON$),     "STR"):@FM
DataFields := "DECOM_NOTE"      :@VM:SQL_Format(Rec(MFC_DECOM_NOTE$),       "STR"):@FM
DataFields := "RANGE"           :@VM:SQL_Format(Rec(MFC_RANGE$),            "DEC", "0")

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

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

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

// MFC_CURR_REACT_NO
If Ans EQ "" AND Rec(MFC_CURR_REACT_NO$) NE "" then
    // List of data fields and their values
    MvFields  = "CURR_REACT_NO":@FM:SQL_Format(Rec(MFC_CURR_REACT_NO$), "INT")
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "MFC_CURR_REACT_NO", Keys, MvFields);
end

Return Ans
