14,661,186 members
Rate this:
See more:
Hallo Experts,

I have done a mathematical equation based on columns and I want to only get the values < 10 and > 10. I have tried using Having but it isn't working. It still shows me the 0 values.

An Example;

Thnx

What I have tried:

```SELECT DISTINCT
ProjectNr,
SUM(GWVS) - SUM(GWVS2) AS GWValue1,
SUM(ABVS) - SUM(GWVS2) AS GWValue2,
SUM(TSVS) - SUM(GWVS2) AS GWValue2
FROM TBL1
WHERE RB IN (North)

GROUP BY ProjectNr

HAVING
SUM(GWVS) - SUM(GWVS2) <>10```
Posted
Updated 25-Aug-16 19:22pm
F-ES Sitecore 25-Aug-16 11:36am

What "values" do you want to be <10 or >10? GWValue1 etc? Do you want those values included in the SUM and just not shown? Or do you want them included from the SUM?
mikybrain1 25-Aug-16 11:52am

Hi The values < or > 10 to be returned should be the one in the HAVING clause
Richard Deeming 25-Aug-16 11:44am

Hardly surprising that it's returning the 0 values, since 0 is less than 10! :)

Click "Improve question" and update your question with a clear and precise description of the problem.

Rate this:

## Solution 1

If you want to exclude 0 values also, then you have to provide this constraint in your query:
```SELECT DISTINCT
ProjectNr,
SUM(GWVS) - SUM(GWVS2) AS GWValue1,
SUM(ABVS) - SUM(GWVS2) AS GWValue2,
SUM(TSVS) - SUM(GWVS2) AS GWValue2
FROM TBL1
WHERE RB IN (North)

GROUP BY ProjectNr

HAVING
(SUM(GWVS) - SUM(GWVS2)) <> 10
AND (SUM(GWVS) - SUM(GWVS2)) <> 0```
Rate this:

## Solution 2

Hi,

Check this...

SQL HAVING Clause[^]

Cheers

Top Experts
Last 24hrsThis month
 Patrice T 170 Richard MacCutchan 130 OriginalGriff 125 Greg Utas 90 RickZeeland 60
 OriginalGriff 3,824 Richard MacCutchan 2,405 CPallini 1,620 Sandeep Mewara 1,215 Richard Deeming 893

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100