Compile function Copy_TOOL_LOG_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given TOOL_LOG record to the MSSQL database.
	
	History
	-------
	07/02/2010    KRF   Original Programmer
\*****************************************************************************/

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

// Parse record into a dimensioned array for speed
Dim Rec(6)
MatParse Record into Rec
					    
// List of key names and their values
Keys  = "TOOL_ID"  :@VM:SQL_Format(Field(Key, "*", 1, 1), "STR"):@FM
Keys := "START_DTM":@VM:SQL_Format(Field(Key, "*", 2, 1), "DATETIME")

// List of data fields and their values
DataFields  = "START_USER"    :@VM:SQL_Format(Rec(1),           "STR"):@FM
DataFields := "START_REASON"  :@VM:SQL_Format(Rec(2),           "STR", 1):@FM
DataFields := "TOOL_MODE"     :@VM:SQL_Format(Rec(3),           "STR"):@FM
DataFields := "STOP_DTM"      :@VM:SQL_Format(Rec(4),           "DATETIME"):@FM
DataFields := "STOP_USER"     :@VM:SQL_Format(Rec(5),           "STR"):@FM

DataFields := "MODE_HRS"      :@VM:SQL_Format({MODE_HRS},       "DEC", 2):@FM
DataFields := "START_DEC"     :@VM:SQL_Format({START_DEC},      "STR"):@FM
DataFields := "START_DT"      :@VM:SQL_Format({START_DT},       "DATE"):@FM
DataFields := "TOOL_CURR_MODE":@VM:SQL_Format({TOOL_CURR_MODE}, "STR"):@FM
DataFields := "TOOL_MODE_DESC":@VM:SQL_Format({TOOL_MODE_DESC}, "STR"):@FM
DataFields := "ACTIVE"        :@VM:SQL_Format({ACTIVE},         "BIT"):@FM
DataFields := "TOOL_DESC"     :@VM:SQL_Format({TOOL_DESC},      "STR"):@FM
DataFields := "TOOL_TYPE"     :@VM:SQL_Format({TOOL_TYPE},      "STR")

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

Return Ans
