Compile function Copy_CUSTOMER_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given CUSTOMER record to the MSSQL database.
	
	History
	-------
	04/21/2010    KRF   Original Programmer
\*****************************************************************************/

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

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

// List of data fields and their values
DataFields  = "ENTRY_DATE"              :@VM:SQL_Format(Rec(4),  "DATE"):@FM
DataFields := "ENTRY_ID"                :@VM:SQL_Format(Rec(5),  "STR"):@FM
DataFields := "ATTENTION"               :@VM:SQL_Format(Rec(6),  "STR"):@FM
DataFields := "COMPANY"                 :@VM:SQL_Format(Rec(7),  "STR"):@FM
DataFields := "CITY"                    :@VM:SQL_Format(Rec(9),  "STR"):@FM
DataFields := "ST"                      :@VM:SQL_Format(Rec(10), "STR"):@FM
DataFields := "ZIP"                     :@VM:SQL_Format(Rec(11), "STR"):@FM
DataFields := "COUNTRY"                 :@VM:SQL_Format(Rec(12), "STR"):@FM
DataFields := "ABBREV"                  :@VM:SQL_Format(Rec(13), "STR"):@FM
DataFields := "SALES_REP"               :@VM:SQL_Format(Rec(18), "STR"):@FM
DataFields := "TERMS"                   :@VM:SQL_Format(Rec(22), "STR"):@FM
DataFields := "BILL_TO_CUST_NO"         :@VM:SQL_Format(Rec(23), "STR"):@FM
DataFields := "SHIPPING_EXPORT_TEMPLATE":@VM:SQL_Format(Rec(25), "STR"):@FM
DataFields := "COA_FOLDER"              :@VM:SQL_Format(Rec(26), "STR"):@FM
DataFields := "VISION_CUST_NO"          :@VM:SQL_Format(Rec(27), "STR"):@FM
DataFields := "VISION_BILL_TO_NO"       :@VM:SQL_Format(Rec(28), "STR"):@FM
DataFields := "SAP_CUST_NO"             :@VM:SQL_Format(Rec(29), "STR"):@FM
DataFields := "SAP_BILL_TO_NO"          :@VM:SQL_Format(Rec(30), "STR")

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

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

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

// Phone Numbers
If Ans EQ "" AND Rec(14) NE "" then
    
    // List of data fields and their values
    MvFields  = "PHONE"     :@FM:SQL_Format(Rec(14), "STR"):@RM
    MvFields := "PHONE_DESC":@FM:SQL_Format(Rec(15), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "CUSTOMER_PHONES", Keys, MvFields);
    
end

// International Phone Numbers
If Ans EQ "" AND Rec(16) NE "" then
    
    // List of data fields and their values
    MvFields  = "INTL_PHONE"     :@FM:SQL_Format(Rec(16), "STR"):@RM
    MvFields := "INTL_PHONE_DESC":@FM:SQL_Format(Rec(17), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "CUSTOMER_INTL_PHONES", Keys, MvFields);
    
end

// Customer Carrier
If Ans EQ "" AND (Rec(19) NE "" OR Rec(20) NE "") then
    
    // List of data fields and their values
    MvFields  = "CARRIER"     :@FM:SQL_Format(Rec(19), "STR"):@RM
    MvFields := "CARRIER_ACCT":@FM:SQL_Format(Rec(20), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "CUSTOMER_CARRIERS", Keys, MvFields);
    
end

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

Return Ans
