Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sub-selects with a having clause

Status
Not open for further replies.
Joined
May 1, 2006
Messages
35
Location
US
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.


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 ~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top