Compile function Copy_CALIB_LIST_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given CALIB_LIST record to the MSSQL database. Since this table
	has multi-value fields, we have to update multiple SQL tables.
	
	History
	-------
	04/05/2010    KRF   Original Programmer
\*****************************************************************************/

$insert CALIB_LIST_EQUATES

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

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

//-----------------------------------------------------------------------------
// CALIB_LIST

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

// List of data fields and their values
DataFields  = "CL_TYPE"     :@VM:SQL_Format(Rec(CALIB_LIST_CL_TYPE$),      "STR"):@FM
DataFields := "EQ_DESC"     :@VM:SQL_Format(Rec(CALIB_LIST_EQ_DESC$),      "STR"):@FM
DataFields := "EQ_SN"       :@VM:SQL_Format(Rec(CALIB_LIST_EQ_SN$),        "STR"):@FM
DataFields := "EQ_LOC"      :@VM:SQL_Format(Rec(CALIB_LIST_EQ_LOC$),       "STR"):@FM
DataFields := "EQ_LEVEL"    :@VM:SQL_Format(Rec(CALIB_LIST_EQ_LEVEL$),     "STR"):@FM
DataFields := "EQ_CAL_CLASS":@VM:SQL_Format(Rec(CALIB_LIST_EQ_CAL_CLASS$), "STR"):@FM
DataFields := "STD_DESC"    :@VM:SQL_Format(Rec(CALIB_LIST_STD_DESC$),     "STR"):@FM
DataFields := "STD_SN"      :@VM:SQL_Format(Rec(CALIB_LIST_STD_SN$),       "STR"):@FM
DataFields := "STD_LOC"     :@VM:SQL_Format(Rec(CALIB_LIST_STD_LOC$),      "STR"):@FM
DataFields := "CAL_INTERVAL":@VM:SQL_Format(Rec(CALIB_LIST_CAL_INTERVAL$), "INT"):@FM
DataFields := "CAL_LOC"     :@VM:SQL_Format(Rec(CALIB_LIST_CAL_LOC$),      "STR"):@FM
DataFields := "ENTER_DTM"   :@VM:SQL_Format(Rec(CALIB_LIST_ENTER_DTM$),    "INT"):@FM

DataFields := "LAST_CAL_DT" :@VM:SQL_Format({LAST_CAL_DT},                 "DATE"):@FM
DataFields := "NEXT_CAL_DT" :@VM:SQL_Format({NEXT_CAL_DT},                 "DATE"):@FM
DataFields := "CAL_LOC_DESC":@VM:SQL_Format({CAL_LOC_DESC},                "STR"):@FM
DataFields := "CAL_NOTES"   :@VM:SQL_Format({CAL_NOTES},                   "STR", 1):@FM
DataFields := "TYPE_DESC"   :@VM:SQL_Format({TYPE_DESC},                   "STR")

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

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

// CALIB_LIST_ORG_NEXT_CAL_DT
If Ans EQ "" AND Rec(CALIB_LIST_ORG_NEXT_CAL_DT$) NE "" then

    // List of data fields and their values
    MvFields  = "ORG_NEXT_CAL_DT":@FM:SQL_Format(Rec(CALIB_LIST_ORG_NEXT_CAL_DT$), "DATE")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "CALIB_LIST_ORG_NEXT_CAL_DT", Keys, MvFields);
    
end

// CALIB_LIST_CAL_DT
CalDT = {CAL_DT}
If Ans EQ "" AND CalDT NE "" then

    // List of data fields and their values
    MvFields  = "CAL_DT":@FM:SQL_Format(CalDT, "DATE")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "CALIB_LIST_CAL_DT", Keys, MvFields);
    
end

Return Ans
