Compile function Copy_PART_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given PART record to the MSSQL database.
	
	History
	-------
	09/08/2010    KRF   Original Programmer
	09/23/2010    KRF   Added symbolics
	09/28/2010    KRF   Added additional fields
	04/21/2012    KRF   Dropped per David's Request, SQL_MFS Removed so this
	                    won't be called
\*****************************************************************************/

$insert PART_EQUATES

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 = "PART_NO":@VM:SQL_Format(Key, "INT")

// List of data fields and their values
DataFields  = "[DESC]"               :@VM:SQL_Format(Rec(PART_DESC$),                  "STR"):@FM
DataFields := "EPI_PART_NO"          :@VM:SQL_Format(Rec(PART_EPI_PART_NO$),           "STR"):@FM
DataFields := "REACT_TYPE"           :@VM:SQL_Format(Rec(PART_REACT_TYPE$),            "STR"):@FM
DataFields := "REACT_OVERHEAD"       :@VM:SQL_Format(Rec(PART_REACT_OVERHEAD$),        "DEC", 2):@FM
DataFields := "CUST_NO"              :@VM:SQL_Format(Rec(PART_CUST_NO$),               "STR"):@FM
DataFields := "CUST_PART_NO"         :@VM:SQL_Format(Rec(PART_CUST_PART_NO$),          "STR"):@FM
DataFields := "CUST_PART_DESC"       :@VM:SQL_Format(Rec(PART_CUST_PART_DESC$),        "STR"):@FM
DataFields := "CUST_PART_NO_INCOMING":@VM:SQL_Format(Rec(PART_CUST_PART_NO_INCOMING$), "STR"):@FM
DataFields := "SUB_PART_NO"          :@VM:SQL_Format(Rec(PART_SUB_PART_NO$),           "STR"):@FM
DataFields := "SUB_PART_REV"         :@VM:SQL_Format(Rec(PART_SUB_PART_REV$),          "STR"):@FM
DataFields := "SUB_SUPPLIER"         :@VM:SQL_Format(Rec(PART_SUB_SUPPLIER$),          "STR"):@FM
DataFields := "SUB_COST"             :@VM:SQL_Format(Rec(PART_SUB_COST$),              "DEC", 2):@FM
DataFields := "ENGINEERING_PART"     :@VM:SQL_Format(Rec(PART_ENGINEERING_PART$),      "BIT"):@FM
DataFields := "SPEC_PROCESSING"      :@VM:SQL_Format(Rec(PART_SPEC_PROCESSING$),       "STR"):@FM
DataFields := "ORD_DET_KEY"          :@VM:SQL_Format(Rec(PART_ORD_DET_KEY$),           "STR"):@FM
DataFields := "PROC_LEAD_TIME"       :@VM:SQL_Format(Rec(PART_PROC_LEAD_TIME$),        "DEC", 1):@FM
DataFields := "CYCLE_TIME"           :@VM:SQL_Format(Rec(PART_CYCLE_TIME$),            "DEC", 1):@FM
DataFields := "PRE_EPI_TIME"         :@VM:SQL_Format(Rec(PART_PRE_EPI_TIME$),          "DEC", 1):@FM
DataFields := "FAB_TIME"             :@VM:SQL_Format(Rec(PART_FAB_TIME$),              "DEC", 1):@FM
DataFields := "POST_TIME"            :@VM:SQL_Format(Rec(PART_POST_TIME$),             "DEC", 1):@FM
DataFields := "PURCH_SPEC_REV"       :@VM:SQL_Format(Rec(PART_PURCH_SPEC_REV$),        "STR"):@FM

// Symbolics
DataFields := "BLOCKED_REACTS"      :@VM:SQL_Format({BLOCKED_REACTS},       "STR"):@FM
DataFields := "CUST_NAME"           :@VM:SQL_Format({CUST_NAME}[1,50],      "STR"):@FM
DataFields := "CUST_PART_KEY"       :@VM:SQL_Format({CUST_PART_KEY},        "STR"):@FM
DataFields := "CUST_SPEC_1"         :@VM:SQL_Format({CUST_SPEC_1},          "STR"):@FM
DataFields := "CUST_SPEC_2"         :@VM:SQL_Format({CUST_SPEC_2},          "STR"):@FM
DataFields := "CUST_SPEC_REV_1"     :@VM:SQL_Format({CUST_SPEC_REV_1},      "STR"):@FM
DataFields := "CUST_SPEC_REV_2"     :@VM:SQL_Format({CUST_SPEC_REV_2},      "STR"):@FM
DataFields := "CUST_TYPE"           :@VM:SQL_Format({CUST_TYPE},            "STR"):@FM
DataFields := "MINUTES_PER_WAFER"   :@VM:SQL_Format({MINUTES_PER_WAFER},    "DEC", 3):@FM
DataFields := "PROVEIN_MIN"         :@VM:SQL_Format({PROVEIN_MIN},          "DEC", 3):@FM
DataFields := "QUAL_REACTS"         :@VM:SQL_Format({QUAL_REACTS},          "STR"):@FM
DataFields := "REACT_TYPE_ALT"      :@VM:SQL_Format({REACT_TYPE_ALT},       "STR"):@FM
DataFields := "REACTOR_TYPE"        :@VM:SQL_Format({REACTOR_TYPE},         "STR"):@FM
DataFields := "SHIP_PSN"            :@VM:SQL_Format({SHIP_PSN},             "STR"):@FM
DataFields := "SPEC_TYPE"           :@VM:SQL_Format({SPEC_TYPE},            "STR"):@FM
DataFields := "SUB_WAFER_SIZE"      :@VM:SQL_Format({SUB_WAFER_SIZE},       "STR"):@FM
DataFields := "SUSCEPTOR_TYPE"      :@VM:SQL_Format({SUSCEPTOR_TYPE},       "STR"):@FM
DataFields := "TUBE_PRESSURE_TYPE"  :@VM:SQL_Format({TUBE_PRESSURE_TYPE},   "STR"):@FM
DataFields := "USE_MAKEUP_WAFERS"   :@VM:SQL_Format({USE_MAKEUP_WAFERS},    "BIT"):@FM
DataFields := "WAND_RESTRICTER"     :@VM:SQL_Format({WAND_RESTRICTER},      "BIT"):@FM
DataFields := "PLANT_CODE"          :@VM:SQL_Format({PLANT_CODE},           "STR"):@FM
DataFields := "PART_YIELD"          :@VM:SQL_Format({PART_YIELD},           "STR"):@FM
DataFields := "MATERIAL_TYPE"       :@VM:SQL_Format({MATERIAL_TYPE},        "STR"):@FM
DataFields := "SUB_TYPE"            :@VM:SQL_Format({SUB_TYPE},             "STR"):@FM
DataFields := "SUB_WAFER_MFR"       :@VM:SQL_Format({SUB_WAFER_MFR},        "STR"):@FM
DataFields := "PURCH_SPEC"          :@VM:SQL_Format({PURCH_SPEC},           "STR"):@FM
DataFields := "HOLD_FLAG"           :@VM:SQL_Format({HOLD_FLAG},            "BIT"):@FM
DataFields := "WO_SIZE_MIN"         :@VM:SQL_Format({WO_SIZE_MIN},          "INT"):@FM
DataFields := "WO_SIZE_MAX"         :@VM:SQL_Format({WO_SIZE_MAX},          "INT"):@FM
DataFields := "THIN_EPI_THICK_TARG" :@VM:SQL_Format({THIN_EPI_THICK_TARG},  "DEC", 2):@FM
DataFields := "THICK_EPI_THICK_TARG":@VM:SQL_Format({THICK_EPI_THICK_TARG}, "DEC", 2):@FM
DataFields := "PSN_ID"              :@VM:SQL_Format({PSN_ID},               "STR"):@FM
DataFields := "STATUS"              :@VM:SQL_Format({STATUS},               "STR"):@FM
DataFields := "SUB_SUPP_BY"         :@VM:SQL_Format({SUB_SUPP_BY},          "STR"):@FM
DataFields := "UOM"                 :@VM:SQL_Format({UOM},                  "STR")

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

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

// PART_PROC_DETAIL
If Ans EQ "" AND (Rec(PART_PROC_STEP_NO$) NE "" OR Rec(PART_PROC_STEP_PSN$) NE "" OR Rec(PART_PROC_STEP_DESC$) NE "") then
    
    // List of data fields and their values
    MvFields  = "PROC_STEP_NO"  :@FM:SQL_Format(Rec(PART_PROC_STEP_NO$),   "INT"):@RM
    MvFields := "PROC_STEP_PSN" :@FM:SQL_Format(Rec(PART_PROC_STEP_PSN$),  "STR"):@RM
    MvFields := "PROC_STEP_DESC":@FM:SQL_Format(Rec(PART_PROC_STEP_DESC$), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "PART_PROC_DETAIL", Keys, MvFields);
    
end

// PART_PROC_STEP_DETAIL
If Ans EQ "" AND (Rec(PART_PROC_STEP_NO$) NE "" OR Rec(PART_PROC_STEP_PSN$) NE "" OR Rec(PART_PROC_STEP_DESC$) NE "") then
    
    // List of data fields and their values
    MvFields  = "PROC_STEP_PSN_STATUS" :@FM:SQL_Format({PROC_STEP_PSN_STATUS}, "STR"):@RM
    MvFields := "PROC_STEP_REACT_TYPE" :@FM:SQL_Format({PROC_STEP_REACT_TYPE}, "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "PART_PROC_STEP_DETAIL", Keys, MvFields);
    
end

Return Ans
