Compile function Copy_EPI_PART_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given EPI_PART record to the MSSQL database.
	
	History
	-------
	04/24/2012    KRF   Original Programmer
	12/27/2017    dmb   Added Export Control (<36>)
\*****************************************************************************/

$insert EPI_PART_EQUATES

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

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

// List of data fields and their values
DataFields  = "EPI_PART_DESC"      :@VM:SQL_Format(Rec(EPI_PART_EPI_PART_DESC$),       "STR"):@FM
DataFields := "SUB_SPEC_NO"        :@VM:SQL_Format(Rec(EPI_PART_SUB_SPEC_NO$),         "STR"):@FM
DataFields := "SUB_SUPP_BY"        :@VM:SQL_Format(Rec(EPI_PART_SUB_SUPP_BY$),         "STR"):@FM
DataFields := "PRODUCT"            :@VM:SQL_Format(Rec(EPI_PART_PRODUCT$),             "STR"):@FM
DataFields := "SUB_WAFER_SIZE"     :@VM:SQL_Format(Rec(EPI_PART_SUB_WAFER_SIZE$),      "STR"):@FM
DataFields := "SUB_ORIENTATION"    :@VM:SQL_Format(Rec(EPI_PART_SUB_ORIENTATION$),     "STR"):@FM
DataFields := "SUB_DOPE_TYPE"      :@VM:SQL_Format(Rec(EPI_PART_SUB_DOPE_TYPE$),       "STR"):@FM
DataFields := "SUB_RES"            :@VM:SQL_Format(Rec(EPI_PART_SUB_RES$),             "STR"):@FM
DataFields := "SUB_RES_UNITS"      :@VM:SQL_Format(Rec(EPI_PART_SUB_RES_UNITS$),       "STR"):@FM
DataFields := "SUB_DOPANT"         :@VM:SQL_Format(Rec(EPI_PART_SUB_DOPANT$),          "STR"):@FM
DataFields := "SUB_POLISH"         :@VM:SQL_Format(Rec(EPI_PART_SUB_POLISH$),          "STR"):@FM
DataFields := "SUB_THICK"          :@VM:SQL_Format(Rec(EPI_PART_SUB_THICK$),           "STR"):@FM
DataFields := "SUB_OXIDE"          :@VM:SQL_Format(Rec(EPI_PART_SUB_OXIDE$),           "STR"):@FM
DataFields := "SUB_BACKSEAL"       :@VM:SQL_Format(Rec(EPI_PART_SUB_BACKSEAL$),        "STR"):@FM
DataFields := "SUB_OXIDE_ANGSTROMS":@VM:SQL_Format(Rec(EPI_PART_SUB_OXIDE_ANGSTROMS$), "STR"):@FM
DataFields := "SUB_MATERIAL"       :@VM:SQL_Format(Rec(EPI_PART_SUB_MATERIAL$),        "STR"):@FM
DataFields := "SPEC_TYPE"          :@VM:SQL_Format(Rec(EPI_PART_SPEC_TYPE$),           "STR"):@FM
DataFields := "SAP_MATERIAL"       :@VM:SQL_Format(Rec(EPI_PART_SAP_MATERIAL$),        "BIT"):@FM
DataFields := "EXPORT_CONTROL"     :@VM:SQL_Format(Rec(EPI_PART_EXPORT_CONTROL$),      "BIT")

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

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

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

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

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

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

// EPI_PART_LAYER_SPEC
If Ans EQ "" AND (Rec(EPI_PART_EPI_LAYER$) NE "" OR Rec(EPI_PART_EPI_STEP$) NE "" OR Rec(EPI_PART_EPI_STEP_LSID$) NE "" OR Rec(EPI_PART_EPI_DOPANT$) NE "" OR Rec(EPI_PART_EPI_THICK_MIN$) NE "" OR Rec(EPI_PART_EPI_THICK_MAX$) NE "" OR Rec(EPI_PART_EPI_RES_MIN$) NE "" OR Rec(EPI_PART_EPI_RES_MAX$) NE "") then
    
    // List of data fields and their values
    MvFields  = "EPI_LAYER"     :@FM:SQL_Format(Rec(EPI_PART_EPI_LAYER$),     "STR"):@RM
    MvFields := "EPI_STEP"      :@FM:SQL_Format(Rec(EPI_PART_EPI_STEP$),      "INT"):@RM
    MvFields := "EPI_STEP_LSID" :@FM:SQL_Format(Rec(EPI_PART_EPI_STEP_LSID$), "STR"):@RM
    MvFields := "EPI_DOPANT"    :@FM:SQL_Format(Rec(EPI_PART_EPI_DOPANT$),    "STR"):@RM
    MvFields := "EPI_THICK_MIN" :@FM:SQL_Format(Rec(EPI_PART_EPI_THICK_MIN$), "DEC", 3):@RM
    MvFields := "EPI_THICK_MAX" :@FM:SQL_Format(Rec(EPI_PART_EPI_THICK_MAX$), "DEC", 3):@RM
    MvFields := "EPI_THICK_TARG":@FM:SQL_Format({EPI_THICK_TARG},             "DEC", 3):@RM
    MvFields := "EPI_RES_MIN"   :@FM:SQL_Format(Rec(EPI_PART_EPI_RES_MIN$),   "DEC", 3):@RM
    MvFields := "EPI_RES_MAX"   :@FM:SQL_Format(Rec(EPI_PART_EPI_RES_MAX$),   "DEC", 3):@RM
    MvFields := "EPI_RES_TARG"  :@FM:SQL_Format({EPI_RES_TARG},               "DEC", 3)
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "EPI_PART_LAYER_SPEC", Keys, MvFields);
    
end

// EPI_PART_SUB_PART_NO
If Ans EQ "" AND (Rec(EPI_PART_SUB_PART_NO$) NE "" OR Rec(EPI_PART_SUB_PART_REV$) NE "" OR Rec(EPI_PART_SUB_MFR$) NE "") then
    
    // List of data fields and their values
    MvFields  = "SUB_PART_NO" :@FM:SQL_Format(Rec(EPI_PART_SUB_PART_NO$),  "STR"):@RM
    MvFields := "SUB_PART_REV":@FM:SQL_Format(Rec(EPI_PART_SUB_PART_REV$), "STR"):@RM
    MvFields := "SUB_MFR"     :@FM:SQL_Format(Rec(EPI_PART_SUB_MFR$),      "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "EPI_PART_SUB_PART_NO", Keys, MvFields);
    
end

// EPI_PART_CUST_EPI_PART_KEY
If Ans EQ "" AND Rec(EPI_PART_CUST_EPI_PART_KEY$) NE "" then
    
    // List of data fields and their values
    // IMPORTANT! Only get the first part of the key because the second part is the key to THIS record
    MvFields = "CUST_NO":@FM:SQL_Format(Rec(EPI_PART_CUST_EPI_PART_KEY$)[1, "*"],  "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "EPI_PART_CUST_EPI_PART_KEY", Keys, MvFields);
    
end

Return Ans
