Good morning my friends,
I have a question about how to optimize a query. Below you will see the query I have created. However it is slow, which doesn’t surprise me.
Is there anything I can do to optimize it or is it better to make it a stored procedure to win time.
The query can take from 1 - 3 seconds… That’s not a real issue in this case but every second I can win is… one extra second
Thanks.
var query =
"SELECT i.quantity4*(CAST(LEFT(i.printingcolours,1) AS INT)+CAST(RIGHT(i.printingcolours,1) AS INT)) FROM orders AS o,orders_items AS i WHERE " +
"i.overview=4 AND o.ordersid=i.ordersid AND " +
"i.printingprocessid=? AND " +
"o.status>2 AND " +
"((i.status IS NULL OR i.status<23) AND (i.statususer IS NULL OR i.statususer='')) AND " +
"(o.onhold IS NULL OR o.onhold=0) AND " +
"(o.incomplete IS NULL OR o.incomplete=0) AND " +
"(o.inproof IS NULL OR o.inproof=0) AND " +
"i.productiondatetime<=? AND o.invoiceitem=0 AND (i.machinesfree IS NULL OR i.machinesfree=0) " +
"ORDER BY o.rushorder DESC,i.productiondatetime ASC";