• 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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DeviVenkataAuthor Commented:
thanks ya

it worked
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.