Compile function Copy_PROD_VER_Record_To_SQL(Connection, Key, Record)

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

$insert PROD_VER_EQUATES

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

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

// List of data fields and their values
DataFields  = "[DESC]"               :@VM:SQL_Format(Rec(PROD_VER_DESC$),                  "STR"):@FM
DataFields := "EPI_PART_NO"          :@VM:SQL_Format(Rec(PROD_VER_EPI_PART_NO$),           "STR"):@FM
DataFields := "REACT_TYPE"           :@VM:SQL_Format(Rec(PROD_VER_REACT_TYPE$),            "STR"):@FM
DataFields := "REACT_OVERHEAD"       :@VM:SQL_Format(Rec(PROD_VER_REACT_OVERHEAD$),        "STR"):@FM
DataFields := "CUST_NO"              :@VM:SQL_Format(Rec(PROD_VER_CUST_NO$),               "STR"):@FM
DataFields := "CUST_PART_NO"         :@VM:SQL_Format(Rec(PROD_VER_CUST_PART_NO$),          "STR"):@FM
DataFields := "CUST_PART_DESC"       :@VM:SQL_Format(Rec(PROD_VER_CUST_PART_DESC$),        "STR"):@FM
DataFields := "CUST_PART_NO_INCOMING":@VM:SQL_Format(Rec(PROD_VER_CUST_PART_NO_INCOMING$), "STR"):@FM
DataFields := "SUB_COST"             :@VM:SQL_Format(Rec(PROD_VER_SUB_COST$),              "STR"):@FM
DataFields := "ENGINEERING_PART"     :@VM:SQL_Format(Rec(PROD_VER_ENGINEERING_PART$),      "BIT"):@FM
DataFields := "SPEC_PROCESSING"      :@VM:SQL_Format(Rec(PROD_VER_SPEC_PROCESSING$),       "STR"):@FM
DataFields := "ORD_DET_KEY"          :@VM:SQL_Format(Rec(PROD_VER_ORD_DET_KEY$),           "STR"):@FM
DataFields := "PROC_LEAD_TIME"       :@VM:SQL_Format(Rec(PROD_VER_PROC_LEAD_TIME$),        "DEC", "1"):@FM
DataFields := "CYCLE_TIME"           :@VM:SQL_Format(Rec(PROD_VER_CYCLE_TIME$),            "DEC", "0"):@FM
DataFields := "PRE_EPI_TIME"         :@VM:SQL_Format(Rec(PROD_VER_PRE_EPI_TIME$),          "DEC", "0"):@FM
DataFields := "FAB_TIME"             :@VM:SQL_Format(Rec(PROD_VER_FAB_TIME$),              "DEC", "0"):@FM
DataFields := "POST_TIME"            :@VM:SQL_Format(Rec(PROD_VER_POST_TIME$),             "DEC", "0"):@FM
DataFields := "PART_YIELD"           :@VM:SQL_Format(Rec(PROD_VER_PART_YIELD$),            "DEC", "1"):@FM
DataFields := "WO_SIZE_MIN"          :@VM:SQL_Format(Rec(PROD_VER_WO_SIZE_MIN$),           "INT"):@FM
DataFields := "WO_SIZE_MAX"          :@VM:SQL_Format(Rec(PROD_VER_WO_SIZE_MAX$),           "INT"):@FM
DataFields := "STATUS"               :@VM:SQL_Format(Rec(PROD_VER_STATUS$),                "STR"):@FM
DataFields := "CREATE_DTM"           :@VM:SQL_Format(Rec(PROD_VER_CREATE_DTM$),            "DATETIME"):@FM
DataFields := "CREATE_BY"            :@VM:SQL_Format(Rec(PROD_VER_CREATE_BY$),             "STR"):@FM
DataFields := "PROD_VER_VER"         :@VM:SQL_Format(Rec(PROD_VER_PROD_VER_VER$),          "INT"):@FM
DataFields := "RET_REJECTS"          :@VM:SQL_Format(Rec(PROD_VER_RET_REJECTS$),           "BIT"):@FM
DataFields := "CASS_SHIP_QTY"        :@VM:SQL_Format(Rec(PROD_VER_CASS_SHIP_QTY$),         "INT"):@FM
DataFields := "EPI_PRO_SHIP_SHORT"   :@VM:SQL_Format(Rec(PROD_VER_EPI_PRO_SHIP_SHORT$),    "BIT"):@FM
DataFields := "XSAP_MAT_TYPE"        :@VM:SQL_Format(Rec(PROD_VER_XSAP_MAT_TYPE$),         "STR"):@FM
DataFields := "CUST_PART_REV"        :@VM:SQL_Format(Rec(PROD_VER_CUST_PART_REV$),         "STR"):@FM
DataFields := "SCHED_NOTES"          :@VM:SQL_Format(Rec(PROD_VER_SCHED_NOTES$),           "STR"):@FM
DataFields := "REMARKS"              :@VM:SQL_Format(Rec(PROD_VER_REMARKS$),               "STR"):@FM

// Symbolics
DataFields := "CUST_NAME"    :@VM:SQL_Format({CUST_NAME}[1,50],     "STR"):@FM
DataFields := "CUST_TYPE"    :@VM:SQL_Format({CUST_TYPE},           "STR"):@FM
DataFields := "MATERIAL_TYPE":@VM:SQL_Format({MATERIAL_TYPE},       "STR"):@FM
DataFields := "PSN_STATUS"   :@VM:SQL_Format({PSN_STATUS},          "STR"):@FM
DataFields := "SAP_MAT_TYPE" :@VM:SQL_Format({SAP_MAT_TYPE},        "STR"):@FM
DataFields := "SHIP_CUST_NO" :@VM:SQL_Format({SHIP_CUST_NO},        "STR"):@FM
DataFields := "SHIP_PSN"     :@VM:SQL_Format({SHIP_PSN},            "STR"):@FM
DataFields := "SPEC_TYPE"    :@VM:SQL_Format({SPEC_TYPE},           "STR")

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

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

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

// PROD_VER_SUB_PART_NO
If Ans EQ "" AND (Rec(PROD_VER_SUB_PART_NO$) NE "" OR Rec(PROD_VER_SUB_SUPPLIER$) NE "" OR Rec(PROD_VER_SUB_PART_REV$) NE "" OR Rec(PROD_VER_SUB_PURCH_SPEC$) NE "" OR Rec(PROD_VER_SUB_PURCH_SPEC_REV$) NE "") then
    
    // List of data fields and their values
    MvFields  = "SUB_PART_NO"       :@FM:SQL_Format(Rec(PROD_VER_SUB_PART_NO$),        "STR"):@RM
    MvFields := "SUB_SUPP_CD"       :@FM:SQL_Format({SUB_SUPP_CD},                     "STR"):@RM
    MvFields := "SUB_SUPPLIER"      :@FM:SQL_Format(Rec(PROD_VER_SUB_SUPPLIER$),       "STR"):@RM
    MvFields := "SUB_PART_REV"      :@FM:SQL_Format(Rec(PROD_VER_SUB_PART_REV$),       "STR"):@RM
    MvFields := "SUB_PURCH_SPEC"    :@FM:SQL_Format(Rec(PROD_VER_SUB_PURCH_SPEC$),     "STR"):@RM
    MvFields := "SUB_PURCH_SPEC_REV":@FM:SQL_Format(Rec(PROD_VER_SUB_PURCH_SPEC_REV$), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "PROD_VER_SUB_PART_NO", Keys, MvFields);
    
end

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

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

// PROD_VER_SHIP_SUB_PART_NO
ShipSubPartNo = {SHIP_SUB_PART_NO}
If Ans EQ "" AND ShipSubPartNo NE "" then
    
    // List of data fields and their values
    MvFields = "SHIP_SUB_PART_NO":@FM:SQL_Format(ShipSubPartNo, "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "PROD_VER_SHIP_SUB_PART_NO", Keys, MvFields);
    
end

Return Ans
