The first part of the code creates a table based on SUM statements:
SELECT varday, COUNT(*) AS Vol,
SUM(FOPS_REHAB) AS FOPS_REHAB,
SUM(FOPS_RECOVERY) AS FOPS_RECOVERY
FROM table
WHERE PROCESSING_DATE > '31/aug/2012' and rownumber =1
GROUP BY varday
ORDER BY varday
However, I have two other code parts that I want to combine into the code above but they have an extra ‘where’ criteria.
So these are the two sum statements I want to combine to the table above;
select SUM(Current_Balance_Amount)as rec_bal, varday
into #temp
from table
where fops_recovery = 1 and PROCESSING_DATE > '31/aug/2012' and rownumber =1
group by varday
ORDER BY varday
select SUM(Current_Balance_Amount)as reh_bal, varday
into #temp
from table
where fops_rehab = 1 and PROCESSING_DATE > '31/aug/2012' and rownumber =1
group by varday
ORDER BY varday
So reh_bal and rec_bal are in one table with the first table which contains FOPS_REHAB and FOPS_RECOVERY. I’m having problems because they have an extra clause (where fops recovery = 1 or fops rehab = 1).
I believe all 3 queries can be combined into one, try this: