Trying to write a query in SqlServer Dev 2017 with SSMS with Object Explorer.
I'm trying to extract all members ( PK) with totals ( Sum(ColumnValues)), below a certain amount. My code extracts all such values except for those that total 0, i.e., my query extracts only the positive values required but not those that are 0. It requires the join of columns C1, C2, from tables T1, T2, with common key K and totaling over column C.
Here's the code:
Select T1.C1, T2.C2, SUM(ColumnValues) FROM T1 join T2 ON T1.K=T2.K GROUP By T1.C1, T2.C2 HAVING SUM(ColumnValues)<100
Code only outputs qualifying _ positive_ values, but not those that are 0. I tried adding a clause, in the ' Having' part as:
Having Sum(ColumnValues)<100 OR Sum(ColumnValues)=0
I even tried writing a stored pro endure that would add 1 to each column value and subtract it after the query is executed, but didn't work. I also tried unioning it with an identical query where I used Having Sum(ColumnValues)=0, which didn't work either. Any suggestions?