Compile function Copy_ORDER_DET_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given ORDER_DET record to the MSSQL database.
	
	History
	-------
	07/12/2010    KRF   Original Programmer
\*****************************************************************************/

$insert ORDER_DET_EQU

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

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

// List of data fields and their values
DataFields  = "QUOTE_NO"           :@VM:SQL_Format(Rec(ORDER_DET_QUOTE_NO$),            "STR"):@FM
DataFields := "QUOTE_ITEM"         :@VM:SQL_Format(Rec(2),                              "STR"):@FM
DataFields := "EPI_PN"             :@VM:SQL_Format(Rec(ORDER_DET_EPI_PN$),              "STR"):@FM
DataFields := "ITEM_DESC"          :@VM:SQL_Format(Rec(ORDER_DET_ITEM_DESC$),           "STR"):@FM
DataFields := "UNIT_PRICE"         :@VM:SQL_Format(Rec(ORDER_DET_UNIT_PRICE$),          "STR"):@FM
DataFields := "ITEM_QTY"           :@VM:SQL_Format(Rec(ORDER_DET_ITEM_QTY$),            "INT"):@FM
DataFields := "WO_NO"              :@VM:SQL_Format(Rec(ORDER_DET_WO_NO$),               "STR"):@FM
DataFields := "INBOUND_TRACKING_NO":@VM:SQL_Format(Rec(ORDER_DET_INBOUND_TRACKING_NO$), "STR"):@FM
DataFields := "PROMISE_DT"         :@VM:SQL_Format(Rec(ORDER_DET_PROMISE_DT$),          "DATE"):@FM
DataFields := "CUST_REQ_DT"        :@VM:SQL_Format(Rec(ORDER_DET_CUST_REQ_DT$),         "DATE"):@FM
DataFields := "REQ_SHIP_DT"        :@VM:SQL_Format(Rec(ORDER_DET_REQ_SHIP_DT$),         "DATE"):@FM
DataFields := "SHIP_WIN_DT"        :@VM:SQL_Format(Rec(ORDER_DET_SHIP_WIN_DT$),         "DATE"):@FM
DataFields := "SUB_PART_NO"        :@VM:SQL_Format(Rec(ORDER_DET_SUB_PART_NO$),         "STR"):@FM
DataFields := "VISION_LINE_NO"     :@VM:SQL_Format(Rec(ORDER_DET_VISION_LINE_NO$),      "STR"):@FM
DataFields := "VISION_ITEM_STATUS" :@VM:SQL_Format(Rec(ORDER_DET_VISION_ITEM_STATUS$),  "STR"):@FM
DataFields := "VISION_PART_TYPE"   :@VM:SQL_Format(Rec(ORDER_DET_VISION_PART_TYPE$),    "STR"):@FM
DataFields := "VISION_SHIP_QTY"    :@VM:SQL_Format(Rec(ORDER_DET_VISION_SHIP_QTY$),     "INT"):@FM
DataFields := "VISION_ATP"         :@VM:SQL_Format(Rec(ORDER_DET_VISION_ATP$),          "STR"):@FM
DataFields := "EXP_RX_DT"          :@VM:SQL_Format(Rec(ORDER_DET_EXP_RX_DT$),           "DATE"):@FM
DataFields := "SUPPLIED_BY"        :@VM:SQL_Format(Rec(ORDER_DET_SUPPLIED_BY$),         "STR"):@FM
DataFields := "ENGINEERING_PART"   :@VM:SQL_Format(Rec(ORDER_DET_ENGINEERING_PART$),    "BIT"):@FM
DataFields := "CUST_PN"            :@VM:SQL_Format(Rec(ORDER_DET_CUST_PN$),             "STR")

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

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

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

// CUST_LOT_INFO
If Ans EQ "" AND Rec(ORDER_DET_CUST_LOT_NO$) NE "" then
    
    // List of data fields and their values
    MvFields  = "CUST_LOT_NO" :@FM:SQL_Format(Rec(ORDER_DET_CUST_LOT_NO$),  "STR"):@RM
    MvFields  = "CUST_LOT_QTY":@FM:SQL_Format(Rec(ORDER_DET_CUST_LOT_QTY$), "INT")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "ORDER_DET_CUST_LOT_INFO", Keys, MvFields);
    
end

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

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

Return Ans
