Compile function Copy_CUST_PART_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given CUST_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
\*****************************************************************************/

$insert CUST_PART_EQUATES

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

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

// List of data fields and their values
DataFields  = "[DESC]"              :@VM:SQL_Format(Rec(CUST_PART_DESC$),                 "STR"):@FM
DataFields := "INBOUND_CUST_PART_NO":@VM:SQL_Format(Rec(CUST_PART_INBOUND_CUST_PART_NO$), "STR"):@FM
DataFields := "PART_NO"             :@VM:SQL_Format(Rec(CUST_PART_PART_NO$),              "STR"):@FM
DataFields := "WO_MIN_WFRS"         :@VM:SQL_Format(Rec(CUST_PART_WO_MIN_WFRS$),          "INT"):@FM
DataFields := "WO_MAX_WFRS"         :@VM:SQL_Format(Rec(CUST_PART_WO_MAX_WFRS$),          "INT"):@FM
DataFields := "SALES_NOTES"         :@VM:SQL_Format(Rec(CUST_PART_SALES_NOTES$),          "STR"):@FM
DataFields := "SHIP_BAG_REQ"        :@VM:SQL_Format(Rec(CUST_PART_SHIP_BAG_REQ$),         "STR"):@FM
DataFields := "SHIP_FULL_TYPE"      :@VM:SQL_Format(Rec(CUST_PART_SHIP_FULL_TYPE$),       "STR"):@FM
DataFields := "SHIP_PARTIAL"        :@VM:SQL_Format(Rec(CUST_PART_SHIP_PARTIAL$),         "BIT"):@FM
DataFields := "SHIP_NCR_REJ"        :@VM:SQL_Format(Rec(CUST_PART_SHIP_NCR_REJ$),         "DEC", 0):@FM
DataFields := "PS_NO"               :@VM:SQL_Format(Rec(CUST_PART_PS_NO$),                "STR"):@FM

// Symbolics
DataFields := "BILL_TO_ADDRESS1"     :@VM:SQL_Format({BILL_TO_ADDRESS1},      "STR"):@FM
DataFields := "BILL_TO_ADDRESS2"     :@VM:SQL_Format({BILL_TO_ADDRESS2},      "STR"):@FM
DataFields := "BILL_TO_ADDRESS3"     :@VM:SQL_Format({BILL_TO_ADDRESS3},      "STR"):@FM
DataFields := "BILL_TO_ATTN"         :@VM:SQL_Format({BILL_TO_ATTN},          "STR"):@FM
DataFields := "BILL_TO_CITY"         :@VM:SQL_Format({BILL_TO_CITY},          "STR"):@FM
DataFields := "BILL_TO_COMPANY"      :@VM:SQL_Format({BILL_TO_COMPANY},       "STR"):@FM
DataFields := "BILL_TO_STATE"        :@VM:SQL_Format({BILL_TO_STATE},         "STR"):@FM
DataFields := "BILL_TO_ZIP"          :@VM:SQL_Format({BILL_TO_ZIP},           "STR"):@FM
DataFields := "BLOCKED_REACTS"       :@VM:SQL_Format({BLOCKED_REACTS},        "STR"):@FM
DataFields := "CUST_ABBREV"          :@VM:SQL_Format({CUST_ABBREV},           "STR"):@FM
DataFields := "CUST_ACCT_REP"        :@VM:SQL_Format({CUST_ACCT_REP},         "STR"):@FM
DataFields := "CUST_ADDR1"           :@VM:SQL_Format({CUST_ADDR1},            "STR"):@FM
DataFields := "CUST_ADDR2"           :@VM:SQL_Format({CUST_ADDR2},            "STR"):@FM
DataFields := "CUST_ADDR3"           :@VM:SQL_Format({CUST_ADDR3},            "STR"):@FM
DataFields := "CUST_BILL_TO_CUST_NO" :@VM:SQL_Format({CUST_BILL_TO_CUST_NO},  "STR"):@FM
DataFields := "CUST_CAPTIVE"         :@VM:SQL_Format({CUST_CAPTIVE},          "BIT"):@FM
DataFields := "CUST_CATEGORY"        :@VM:SQL_Format({CUST_CATEGORY},         "STR"):@FM
DataFields := "CUST_CITY"            :@VM:SQL_Format({CUST_CITY},             "STR"):@FM
DataFields := "CUST_CONSIGNMENT"     :@VM:SQL_Format({CUST_CONSIGNMENT},      "BIT"):@FM
DataFields := "CUST_COUNTRY"         :@VM:SQL_Format({CUST_COUNTRY},          "STR"):@FM
DataFields := "CUST_DIVISION"        :@VM:SQL_Format({CUST_DIVISION},         "STR"):@FM
DataFields := "CUST_INCO_CODE"       :@VM:SQL_Format({CUST_INCO_CODE},        "STR"):@FM
DataFields := "CUST_INCO_DESC"       :@VM:SQL_Format({CUST_INCO_DESC},        "STR"):@FM
DataFields := "CUST_INTL_PHONE1"     :@VM:SQL_Format({CUST_INTL_PHONE1},      "STR"):@FM
DataFields := "CUST_INTL_PHONE2"     :@VM:SQL_Format({CUST_INTL_PHONE2},      "STR"):@FM
DataFields := "CUST_INTL_PHONE_TYPE1":@VM:SQL_Format({CUST_INTL_PHONE_TYPE1}, "STR"):@FM
DataFields := "CUST_INTL_PHONE_TYPE2":@VM:SQL_Format({CUST_INTL_PHONE_TYPE2}, "STR"):@FM
DataFields := "CUST_INVOICE_NOTES"   :@VM:SQL_Format({CUST_INVOICE_NOTES},    "STR"):@FM
DataFields := "CUST_MU_WAFERS"       :@VM:SQL_Format({CUST_MU_WAFERS},        "BIT"):@FM
DataFields := "CUST_NAME"            :@VM:SQL_Format({CUST_NAME}[1,50],       "STR"):@FM
DataFields := "CUST_NOTE"            :@VM:SQL_Format({CUST_NOTE},             "STR"):@FM
DataFields := "CUST_PHONE1"          :@VM:SQL_Format({CUST_PHONE1},           "STR"):@FM
DataFields := "CUST_PHONE2"          :@VM:SQL_Format({CUST_PHONE2},           "STR"):@FM
DataFields := "CUST_PHONE_TYPE1"     :@VM:SQL_Format({CUST_PHONE_TYPE1},      "STR"):@FM
DataFields := "CUST_PHONE_TYPE2"     :@VM:SQL_Format({CUST_PHONE_TYPE2},      "STR"):@FM
DataFields := "CUST_REPORT_EXCLUDE"  :@VM:SQL_Format({CUST_REPORT_EXCLUDE},   "BIT"):@FM
DataFields := "CUST_STATE"           :@VM:SQL_Format({CUST_STATE},            "STR"):@FM
DataFields := "CUST_STATUS"          :@VM:SQL_Format({CUST_STATUS},           "STR"):@FM
DataFields := "CUST_TYPE"            :@VM:SQL_Format({CUST_TYPE},             "STR"):@FM
DataFields := "CUST_ZIP"             :@VM:SQL_Format({CUST_ZIP},              "STR"):@FM
DataFields := "PART_DESC"            :@VM:SQL_Format({PART_DESC},             "STR"):@FM
DataFields := "PART_EPI_PART"        :@VM:SQL_Format({PART_EPI_PART},         "STR"):@FM
DataFields := "PART_OLD_DATA"        :@VM:SQL_Format({PART_OLD_DATA},         "STR"):@FM
DataFields := "PART_PSN"             :@VM:SQL_Format({PART_PSN},              "STR"):@FM
DataFields := "PART_REACT_TYPE"      :@VM:SQL_Format({PART_REACT_TYPE},       "STR"):@FM
DataFields := "PART_SUB_PART_NO"     :@VM:SQL_Format({PART_SUB_PART_NO},      "STR"):@FM
DataFields := "QUAL_REACTS"          :@VM:SQL_Format({QUAL_REACTS},           "STR"):@FM
DataFields := "SHIP_ACCT_NO1"        :@VM:SQL_Format({SHIP_ACCT_NO1},         "STR"):@FM
DataFields := "SHIP_ACCT_NO2"        :@VM:SQL_Format({SHIP_ACCT_NO2},         "STR"):@FM
DataFields := "SHIP_ACCT_NO3"        :@VM:SQL_Format({SHIP_ACCT_NO3},         "STR"):@FM
DataFields := "SHIP_TO_ADDR1"        :@VM:SQL_Format({SHIP_TO_ADDR1},         "STR"):@FM
DataFields := "SHIP_TO_ADDR2"        :@VM:SQL_Format({SHIP_TO_ADDR2},         "STR"):@FM
DataFields := "SHIP_TO_ADDR3"        :@VM:SQL_Format({SHIP_TO_ADDR3},         "STR"):@FM
DataFields := "SHIP_TO_ATTN"         :@VM:SQL_Format({SHIP_TO_ATTN},          "STR"):@FM
DataFields := "SHIP_TO_CITY"         :@VM:SQL_Format({SHIP_TO_CITY},          "STR"):@FM
DataFields := "SHIP_TO_COMPANY"      :@VM:SQL_Format({SHIP_TO_COMPANY},       "STR"):@FM
DataFields := "SHIP_TO_STATE"        :@VM:SQL_Format({SHIP_TO_STATE},         "STR"):@FM
DataFields := "SHIP_TO_ZIP"          :@VM:SQL_Format({SHIP_TO_ZIP},           "STR"):@FM
DataFields := "SHIPPER_INFO1"        :@VM:SQL_Format({SHIPPER_INFO1},         "STR"):@FM
DataFields := "SHIPPER_INFO2"        :@VM:SQL_Format({SHIPPER_INFO2},         "STR"):@FM
DataFields := "SHIPPER_INFO3"        :@VM:SQL_Format({SHIPPER_INFO3},         "STR"):@FM
DataFields := "SPEC_DESC1"           :@VM:SQL_Format({SPEC_DESC1},            "STR"):@FM
DataFields := "SPEC_DESC2"           :@VM:SQL_Format({SPEC_DESC2},            "STR"):@FM
DataFields := "SPEC_DESC3"           :@VM:SQL_Format({SPEC_DESC3},            "STR"):@FM
DataFields := "SPEC_HARDCOPY1"       :@VM:SQL_Format({SPEC_HARDCOPY1},        "BIT"):@FM
DataFields := "SPEC_HARDCOPY2"       :@VM:SQL_Format({SPEC_HARDCOPY2},        "BIT"):@FM
DataFields := "SPEC_HARDCOPY3"       :@VM:SQL_Format({SPEC_HARDCOPY3},        "BIT"):@FM
DataFields := "SPEC_NO1"             :@VM:SQL_Format({SPEC_NO1},              "STR"):@FM
DataFields := "SPEC_NO2"             :@VM:SQL_Format({SPEC_NO2},              "STR"):@FM
DataFields := "SPEC_NO3"             :@VM:SQL_Format({SPEC_NO3},              "STR"):@FM
DataFields := "SPEC_REV1"            :@VM:SQL_Format({SPEC_REV1},             "STR"):@FM
DataFields := "SPEC_REV2"            :@VM:SQL_Format({SPEC_REV2},             "STR"):@FM
DataFields := "SPEC_REV3"            :@VM:SQL_Format({SPEC_REV3},             "STR"):@FM
DataFields := "SPEC_REV_DT1"         :@VM:SQL_Format({SPEC_REV_DT1},          "DATE"):@FM
DataFields := "SPEC_REV_DT2"         :@VM:SQL_Format({SPEC_REV_DT2},          "DATE"):@FM
DataFields := "SPEC_REV_DT3"         :@VM:SQL_Format({SPEC_REV_DT3},          "DATE"):@FM
DataFields := "SPEC_SHIP_INST"       :@VM:SQL_Format({SPEC_SHIP_INST},        "STR")

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

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

// CUST_PART_SPEC_DETAIL
If Ans EQ "" AND (Len(Rec(CUST_PART_SPEC_NO$)) OR Len(Rec(CUST_PART_SPEC_REV$)) OR Len(Rec(CUST_PART_SPEC_REV_DT$)) OR Len(Rec(CUST_PART_SPEC_DESC$)) OR Len(Rec(CUST_PART_SPEC_HARDCOPY$))) then
    
    // List of data fields and their values
    MvFields  = "SPEC_NO"      :@FM:SQL_Format(Rec(CUST_PART_SPEC_NO$),       "STR"):@RM
    MvFields := "SPEC_REV"     :@FM:SQL_Format(Rec(CUST_PART_SPEC_REV$),      "STR"):@RM
    MvFields := "SPEC_REV_DT"  :@FM:SQL_Format(Rec(CUST_PART_SPEC_REV_DT$),   "DATE"):@RM
    MvFields := "SPEC_DESC"    :@FM:SQL_Format(Rec(CUST_PART_SPEC_DESC$),     "STR"):@RM
    MvFields := "SPEC_HARDCOPY":@FM:SQL_Format(Rec(CUST_PART_SPEC_HARDCOPY$), "BIT")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "CUST_PART_SPEC_DETAIL", Keys, MvFields);
    
end

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

Return Ans
