Compile function Copy_WO_MAST_SCHED_Record_To_SQL(Connection, Key, Record)

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

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

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

// List of data fields and their values
DataFields  = "WO_NO"             :@VM:SQL_Format(Rec(2),  "INT"):@FM
DataFields := "RDS_COMP"          :@VM:SQL_Format(Rec(3),  "INT"):@FM
DataFields := "EVENT"             :@VM:SQL_Format(Rec(4),  "STR"):@FM
DataFields := "HOT"               :@VM:SQL_Format(Rec(5),  "BIT"):@FM
DataFields := "PSN_NO"            :@VM:SQL_Format(Rec(6),  "STR"):@FM
DataFields := "RELEASED"          :@VM:SQL_Format(Rec(7),  "BIT"):@FM
DataFields := "CUST_NO"           :@VM:SQL_Format(Rec(8),  "INT"):@FM
DataFields := "WO_STATUS"         :@VM:SQL_Format(Rec(9),  "STR"):@FM
DataFields := "RDS_COUNT"         :@VM:SQL_Format(Rec(10), "INT"):@FM
DataFields := "NOTES"             :@VM:SQL_Format(Rec(11), "STR"):@FM
DataFields := "PART_NO"           :@VM:SQL_Format(Rec(12), "STR"):@FM
DataFields := "EPI_PART_NO"       :@VM:SQL_Format(Rec(13), "STR"):@FM
DataFields := "SCHED_DT"          :@VM:SQL_Format(Rec(14), "DATE"):@FM
DataFields := "START_DATE"        :@VM:SQL_Format(Rec(14), "DATE"):@FM
DataFields := "REACT_NO"          :@VM:SQL_Format(Rec(15), "INT"):@FM
DataFields := "START_TIME"        :@VM:SQL_Format(Rec(16), "TIME"):@FM
DataFields := "LOCKED"            :@VM:SQL_Format(Rec(17), "BIT"):@FM
DataFields := "TAR_THICK"         :@VM:SQL_Format(Rec(18), "STR"):@FM
DataFields := "TAR_RESIST"        :@VM:SQL_Format(Rec(19), "STR"):@FM
DataFields := "PROC_TIME"         :@VM:SQL_Format(Rec(20), "INT"):@FM
DataFields := "END_DATE"          :@VM:SQL_Format(Rec(21), "DATE"):@FM
DataFields := "END_TIME"          :@VM:SQL_Format(Rec(22), "TIME"):@FM
DataFields := "DOPANT"            :@VM:SQL_Format(Rec(23), "STR"):@FM
DataFields := "SOURCE_GAS"        :@VM:SQL_Format(Rec(24), "STR"):@FM
DataFields := "RUN_TYPE"          :@VM:SQL_Format(Rec(25), "STR"):@FM
DataFields := "QUALIFIED"         :@VM:SQL_Format(Rec(26), "STR"):@FM
DataFields := "BLOCKED"           :@VM:SQL_Format(Rec(27), "STR"):@FM
DataFields := "FIXED_PROC_TIME"   :@VM:SQL_Format(Rec(28), "BIT"):@FM
DataFields := "STOPPAGE"          :@VM:SQL_Format(Rec(29), "DEC", "0"):@FM
DataFields := "LAST_MODIFIED_BY"  :@VM:SQL_Format(Rec(30), "STR"):@FM
DataFields := "LAST_MODIFIED_DATE":@VM:SQL_Format(Rec(31), "DATE"):@FM
DataFields := "LAST_MODIFIED_TIME":@VM:SQL_Format(Rec(32), "TIME")

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

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

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

Return Ans
