Hi,
I need to calculate total amount as (quantity + ship+cancel) * price. The ship or cancel fields can be null. What function I can use to replace NULL with 0 ?
Here a samples which give me error:
var vServer = databaseManager.getDataSourceServerName(controller.getDataSource())
var arg = new Array();
arg[0] = 21;
_query = "select price * (quantity+((isNaN(ship) ? 0 : ship) + ((isNaN(cancel) ? 0 : cancel) ) from orderdetail where orderid = ? "
var _dset = databaseManager.getDataSetByQuery(vServer, _query, arg, 10000);
If use QB Builder it doesn’t give error but result wrong ( if for example, ship is null and cancel not null the result will be calculation of price * qty and cancel was not included in calculation)
var q1 = databaseManager.createSelect(‘db:/pcd/orderdetail’)
q1.where.add(q1.columns[‘orderid’].eq(vOrderID))
q1.result.clear()
q1.result.add(q1.columns[‘price’].multiply(q1.columns[‘quantity’].plus(isNaN(q1.columns[‘ship’]) ? 0 : q1.columns[‘ship’]).plus(isNaN(q1.columns[‘cancel’]) ? 0 : q1.columns[‘cancel’])))
var _dset1 = databaseManager.getDataSetByQuery(q1, -1)