Avatar of martgriff

asked on 

SQL Sub-Query

I have the below query which has a sub query in it. This has 2 having clauses however it dosent like the second one where removedate should be null. Get message saying cant have 2 conditions in a sub query, how can i get round this or what have i dont wrong

SELECT DISTINCT dbo.tbl_property.PROPREF, dbo.tbl_property.APPLIANCENO,
                          (SELECT     COUNT(AssetAppID) AS AssetAppIDS
                            FROM          dbo.tbl_appliance
                            WHERE      (propref = N'1dum')
                            GROUP BY AssetAppID, removedate
                            HAVING      (COUNT(AssetAppID) IS NOT NULL) AND (removedate IS NULL)) AS ASSETAPPID
FROM         dbo.tbl_property INNER JOIN
                      dbo.tbl_appliance AS tbl_appliance_1 ON dbo.tbl_property.PROPREF = tbl_appliance_1.propref
WHERE     (dbo.tbl_property.PROPREF = N'1dum')

Avatar of undefined
Last Comment

8/22/2022 - Mon