I am trying to speed up a stored procedure, and have the following subqueries:
SELECT
...
ISNULL((SELECT Table1.Order WHERE Table2.STATUS <> 'R'),0) AS 'Order',
ISNULL((SELECT Table1.Order WHERE Table2.STATUS = 'R'),0) AS 'Reject',
...
FROM Table1
LEFT JOIN
Table2
ON Table1.KEY=Table2.KEY
Is there a way to more efficiently write the above?
I was thinking an IF statement or something, but not quite sure how to write it.
I'm asking this because I read that it's good to minimize subqueries to improve performance.