• C

ESQL C programming to create XLS file


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);
    fprintf(gszReportFileName,"\t\t<Cell><Data ss:Type='Number'>%4lf</Data></Cell>\n <\Row>\n",  0.0000);

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


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.

DeviVenkataAuthor Commented:
thanks ya

it worked
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.