Compile function Copy_TOOL_Record_To_SQL(Connection, Key, Record)

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

$insert TOOL_EQUATES

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

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

// List of data fields and their values
DataFields  = "TOOL_DESC"     :@VM:SQL_Format(Rec(TOOL_TOOL_DESC$),      "STR"):@FM
DataFields := "TOOL_TYPE"     :@VM:SQL_Format(Rec(TOOL_TOOL_TYPE$),      "STR"):@FM
DataFields := "OUT_OF_SERVICE":@VM:SQL_Format(Rec(TOOL_OUT_OF_SERVICE$), "BIT"):@FM
DataFields := "VENDOR"        :@VM:SQL_Format(Rec(TOOL_VENDOR$),         "STR"):@FM
DataFields := "LOCATIONX"     :@VM:SQL_Format(Rec(TOOL_LOCATIONX$),      "STR"):@FM
DataFields := "BATCH"         :@VM:SQL_Format(Rec(TOOL_BATCH$),          "BIT"):@FM

// Symbolics
DataFields := "LOCATION"      :@VM:SQL_Format({LOCATION},                "STR"):@FM
DataFields := "AREA"          :@VM:SQL_Format({AREA},                    "STR"):@FM
DataFields := "TOOL_WH_CD"    :@VM:SQL_Format({TOOL_WH_DESC},            "STR"):@FM
DataFields := "TOOL_LOC_CD"   :@VM:SQL_Format({TOOL_LOC_DESC},           "STR")

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

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

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

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

Return Ans
