navigator703
MIS
Happy New Year,
I am working on a subselect query with a having statement at the end. The having statement will eliminate all differences that are not zero. I only want to see where the differences are not zero. This will hopefull reduce the amount of results.
Let me know if you have any suggestions.
~ a journey of a thousand miles must begin with a single step ~
I am working on a subselect query with a having statement at the end. The having statement will eliminate all differences that are not zero. I only want to see where the differences are not zero. This will hopefull reduce the amount of results.
Code:
SELECT P.PRPTY_ID, P.PRPTY_NM, P.CO_CD, P.CST_CTR_CD,
SUM (O.OCCPT_RSF_QTY) AS 'SNAPSHOT OCCPT RSF',
(SELECT ISNULL (SUM (OS.OCCPT_RSF_QTY), 0)
FROM D_REDSKINS.DBO.T_OCCPT OS
WHERE P.PRPTY_ID = OS.PRPTY_ID AND OS.CO_CD <> '3333') AS 'CURRENT OCCPT RSF',
(SELECT (SUM (O.OCCPT_RSF_QTY)) - ISNULL ((SUM (OS.OCCPT_RSF_QTY)), 0)
FROM D_REDSKINS.DBO.T_OCCPT OS
WHERE P.PRPTY_ID = OS.PRPTY_ID AND OS.CO_CD <> '3333') AS 'DIFFERENCE'
FROM T_PRPTY P INNER JOIN T_OCCPT O ON P.PRPTY_ID = O.PRPTY_ID
WHERE O.CO_CD <> '3333'
GROUP BY P.PRPTY_ID, P.PRPTY_NM, P.CO_CD, P.CST_CTR_CD
HAVING ((SUM (O.OCCPT_RSF_QTY)) - ISNULL ((SUM (OS.OCCPT_RSF_QTY)), 0) <> 0)
Let me know if you have any suggestions.
~ a journey of a thousand miles must begin with a single step ~