Compile function Copy_FISCAL_QTR_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given FISCAL_QTR record to the MSSQL database.
	
	History
	-------
	08/09/2010    KRF   Original Programmer
\*****************************************************************************/

$insert FISCAL_QTR_EQUATES

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

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

// List of data fields and their values
DataFields  = "START_DT"         :@VM:SQL_Format(Rec(FISCAL_QTR_START_DT$), "DATE"):@FM
DataFields := "END_DT"           :@VM:SQL_Format(Rec(FISCAL_QTR_END_DT$),   "DATE"):@FM
DataFields := "TOT_DAYS"         :@VM:SQL_Format({TOT_DAYS},                "INT"):@FM
DataFields := "PLAN_WORKING_DAYS":@VM:SQL_Format({PLAN_WORKING_DAYS},       "INT")

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

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

// FISCAL_QTR_TARGETS
If Ans EQ "" AND Rec(FISCAL_QTR_THRU_GROUP$) NE "" then
    
    // List of data fields and their values
    MvFields  = "THRU_GROUP" :@FM:SQL_Format(Rec(FISCAL_QTR_THRU_GROUP$),  "STR"):@RM
    MvFields := "THRU_TARGET":@FM:SQL_Format(Rec(FISCAL_QTR_THRU_TARGET$), "STR"):@RM
    MvFields := "THRU_QTY"   :@FM:SQL_Format(Rec(FISCAL_QTR_THRU_QTY$),    "INT"):@RM
    MvFields := "THRU_PCNT"  :@FM:SQL_Format(Rec(FISCAL_QTR_THRU_PCNT$),   "DEC", 2)
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "FISCAL_QTR_TARGETS", Keys, MvFields);
    
end

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

Return Ans
