Is it possible to complete a mySQL query when second or any next parameter but first is null ?
For example I generate a report based on a given date (datereport) for a single item (itemreport).
Now when no item is selected to the frontend and its req.query.itemreport gets null, the rest of the query has to be executed considering that user asked for all items and not for a single one without stopping the execution because it gets null parameter (itemreport).
reportsdateres.post(function(req, res, next) {
datereport = req.query.datereport;
itemreport = req.query.itemreport; // this can be null for querying all items
req.getConnection(function(err, conn) {
if (err) return next("Cannot Connect");
var query = conn.query("SELECT SUM(total_profit) AS fee_total FROM transactions WHERE date_created = ? AND item = ?", [datereport, itemreport], function(err, rows) {
// ^^^^^^^^^^^^
// do myStuff
});
});
});