• C

ESQL C programming to create XLS file

Hi,

Iam getting an "-NaNQ" error on writing float values into xls.

/* Following is the query which gets the sum of 2 amounts (decimal values)from a table*/
sprintf(szSQLSelect,"Select case when (select sum(ac.amt1+ac.amt2) from "
                                 "Account_table ac ) <= 0 then 0.0000 else " 
                                " (select sum(ac.amt1+ac.amt2) from Account_table ac ) end actual");

/* the query is excuted and the actual amount is fetched into the float variable "factualamt" */
$double factualamt;
EXEC SQL FETCH POWeeklySelectStmt_c INTO :factualamt;

/* Now im writing that value into the xml file as follows */
    fprintf(gszReportFileName,"<Row> \n");
   if( fActualAmt != 0.0000  ){
 fprintf(gszReportFileName,"\t\t<Cell><Data ss:Type='Number'>%4lf</Data></Cell>\n <\Row>\n",  fActualAmt);
    }
     else{
    fprintf(gszReportFileName,"\t\t<Cell><Data ss:Type='Number'>%4lf</Data></Cell>\n <\Row>\n",  0.0000);
     }


Error:
But when i execute the program , i get an error while opening the xls saying that the data is an "-NaNQ"

Cause for error:
This error occurs whenever the amount value in the table is NULL.

Please help me with this issue

Regards
Devi

DeviVenkataAsked:
Who is Participating?
 
itsmeandnobodyelseConnect With a Mentor Commented:
>>>> This error occurs whenever the amount value in the table is NULL.

Use COALESCE function in sql to avoid NULL (nil) values returned.

select sum(coalesce(ac.amt1, 0.0) + coalesce(ac.amt2, 0.0))

You also could check in the where clause that you have valid numbers.



0
 
DeviVenkataAuthor Commented:
thanks ya

it worked
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.