Compile function Copy_CUST_EPI_PART_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given CUST_EPI_PART record to the MSSQL database.
	
	History
	-------
	04/24/2012    KRF   Original Programmer
\*****************************************************************************/

$insert CUST_EPI_PART_EQUATES

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

// Parse record into a dimensioned array for speed
Dim Rec(45)
MatParse Record into Rec

// List of key names and their values
Keys  = "CUST_NO":@VM:SQL_Format(Field(Key, "*", 1), "STR"):@FM
Keys := "EPI_PN" :@VM:SQL_Format(Field(Key, "*", 2), "STR")

// List of data fields and their values
DataFields  = "SALES_NOTES"             :@VM:SQL_Format(Rec(CUST_EPI_PART_SALES_NOTES$),              "STR"):@FM
DataFields := "SHIP_INST"               :@VM:SQL_Format(Rec(CUST_EPI_PART_SHIP_INST$),                "STR"):@FM
DataFields := "SHIP_CUST_RDS"           :@VM:SQL_Format(Rec(CUST_EPI_PART_SHIP_CUST_RDS$),            "BIT"):@FM
DataFields := "SHIP_COC_FRONT"          :@VM:SQL_Format(Rec(CUST_EPI_PART_SHIP_COC_FRONT$),           "BIT"):@FM
DataFields := "SHIP_COC_BACK"           :@VM:SQL_Format(Rec(CUST_EPI_PART_SHIP_COC_BACK$),            "BIT"):@FM
DataFields := "SHIP_PARTIAL"            :@VM:SQL_Format(Rec(CUST_EPI_PART_SHIP_PARTIAL$),             "BIT"):@FM
DataFields := "SHIP_NCR_REJ"            :@VM:SQL_Format(Rec(CUST_EPI_PART_SHIP_NCR_REJ$),             "DEC", "0"):@FM
DataFields := "SHIP_FULL_TYPE"          :@VM:SQL_Format(Rec(CUST_EPI_PART_SHIP_FULL_TYPE$),           "STR"):@FM
DataFields := "SHIP_BAG_REQ"            :@VM:SQL_Format(Rec(CUST_EPI_PART_SHIP_BAG_REQ$),             "STR"):@FM
DataFields := "SHIP_COC_FRONT_COPIES"   :@VM:SQL_Format(Rec(CUST_EPI_PART_SHIP_COC_FRONT_COPIES$),    "INT"):@FM
DataFields := "SHIP_COC_BACK_COPIES"    :@VM:SQL_Format(Rec(CUST_EPI_PART_SHIP_COC_BACK_COPIES$),     "INT"):@FM
DataFields := "MONITOR_WAFER_LABEL"     :@VM:SQL_Format(Rec(CUST_EPI_PART_MONITOR_WAFER_LABEL$),      "BIT"):@FM
DataFields := "MAKEUP_WAFERS"           :@VM:SQL_Format(Rec(CUST_EPI_PART_MAKEUP_WAFERS$),            "BIT"):@FM
DataFields := "TW_RET_INST"             :@VM:SQL_Format(Rec(CUST_EPI_PART_TW_RET_INST$),              "STR"):@FM
DataFields := "WMO_LOAD_CNT"            :@VM:SQL_Format(Rec(CUST_EPI_PART_WMO_LOAD_CNT$),             "INT"):@FM
DataFields := "RET_REJECTS"             :@VM:SQL_Format(Rec(CUST_EPI_PART_RET_REJECTS$),              "BIT"):@FM
DataFields := "EPI_PRO_SHIP_SHORT"      :@VM:SQL_Format(Rec(CUST_EPI_PART_EPI_PRO_SHIP_SHORT$),       "BIT"):@FM
DataFields := "BILL_INST"               :@VM:SQL_Format(Rec(CUST_EPI_PART_BILL_INST$),                "STR"):@FM
DataFields := "CASS_SHIP_QTY"           :@VM:SQL_Format(Rec(CUST_EPI_PART_CASS_SHIP_QTY$),            "INT"):@FM
DataFields := "TR_SRP"                  :@VM:SQL_Format(Rec(CUST_EPI_PART_TR_SRP$),                   "BIT"):@FM
DataFields := "TR_FTIR"                 :@VM:SQL_Format(Rec(CUST_EPI_PART_TR_FTIR$),                  "BIT"):@FM
DataFields := "TR_HGPROBE"              :@VM:SQL_Format(Rec(CUST_EPI_PART_TR_HGPROBE$),               "BIT"):@FM
DataFields := "TR_TENCOR"               :@VM:SQL_Format(Rec(CUST_EPI_PART_TR_TENCOR$),                "BIT"):@FM
DataFields := "TR_STRESS"               :@VM:SQL_Format(Rec(CUST_EPI_PART_TR_STRESS$),                "BIT"):@FM
DataFields := "TR_TEST_WAFER"           :@VM:SQL_Format(Rec(CUST_EPI_PART_TR_TEST_WAFER$),            "BIT"):@FM
DataFields := "TR_SRP_WWAFER"           :@VM:SQL_Format(Rec(CUST_EPI_PART_TR_SRP_WWAFER$),            "BIT"):@FM
DataFields := "TR_4PP"                  :@VM:SQL_Format(Rec(CUST_EPI_PART_TR_4PP$),                   "BIT"):@FM
DataFields := "CUST_RDS_CLEANROOM_PAPER":@VM:SQL_Format(Rec(CUST_EPI_PART_CUST_RDS_CLEANROOM_PAPER$), "BIT")

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

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

// CUST_EPI_PART_SPEC
If Ans EQ "" AND (Rec(CUST_EPI_PART_SPEC_NO$) NE "" OR Rec(CUST_EPI_PART_SPEC_DESC$) NE "" OR Rec(CUST_EPI_PART_SPEC_REV$) NE "" OR Rec(CUST_EPI_PART_SPEC_REV_DT$) NE "" OR Rec(CUST_EPI_PART_SPEC_HARDCOPY$) NE "") then
    
    // List of data fields and their values
    MvFields  = "SPEC_NO"      :@FM:SQL_Format(Rec(CUST_EPI_PART_SPEC_NO$),       "STR"):@RM
    MvFields := "SPEC_DESC"    :@FM:SQL_Format(Rec(CUST_EPI_PART_SPEC_DESC$),     "STR"):@RM
    MvFields := "SPEC_REV"     :@FM:SQL_Format(Rec(CUST_EPI_PART_SPEC_REV$),      "STR"):@RM
    MvFields := "SPEC_REV_DT"  :@FM:SQL_Format(Rec(CUST_EPI_PART_SPEC_REV_DT$),   "DATE"):@RM
    MvFields := "SPEC_HARDCOPY":@FM:SQL_Format(Rec(CUST_EPI_PART_SPEC_HARDCOPY$), "BIT")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "CUST_EPI_PART_SPEC", Keys, MvFields);
    
end

// CUST_EPI_PART_CUST_PART
If Ans EQ "" AND (Rec(CUST_EPI_PART_CUST_PART_NO$) NE "" OR Rec(CUST_EPI_PART_CUST_PART_REV$) NE "" OR Rec(CUST_EPI_PART_CUST_PART_NO_INBOUND$) NE "" OR Rec(CUST_EPI_PART_CUST_PART_DESC$) NE "") then
    
    // List of data fields and their values
    MvFields  = "CUST_PART_NO"        :@FM:SQL_Format(Rec(CUST_EPI_PART_CUST_PART_NO$),         "STR"):@RM
    MvFields := "CUST_PART_REV"       :@FM:SQL_Format(Rec(CUST_EPI_PART_CUST_PART_REV$),        "STR"):@RM
    MvFields := "CUST_PART_NO_INBOUND":@FM:SQL_Format(Rec(CUST_EPI_PART_CUST_PART_NO_INBOUND$), "STR"):@RM
    MvFields := "CUST_PART_DESC"      :@FM:SQL_Format(Rec(CUST_EPI_PART_CUST_PART_DESC$),       "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "CUST_EPI_PART_CUST_PART", Keys, MvFields);
    
end

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

Return Ans
