SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Multiple AND in having
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mitasid
Yak Posting Veteran

New Zealand
51 Posts

Posted - 08/21/2006 :  23:47:56  Show Profile  Reply with Quote
Hi Guys

I need to use 3 conditions using AND in my query.
Its in the following format:

SELECT Indicatorid, DHBName, PHOName, PracticeName, SUM(Numerator) AS Expr1, SUM(Denominator) AS Expr2
FROM PhoNew
GROUP BY Indicatorid, DHBName, PHOName, PracticeName
HAVING indicator id = 1 AND dhb name = 'canterbury dhb ' AND practicename = 'canterbury community pho- 585342'


If i use two conditions in AND, query works correctly but when i use the third conditions, I get a syntax error

Please help

Thanks
Mita

khtan
In (Som, Ni, Yak)

Singapore
17584 Posts

Posted - 08/21/2006 :  23:56:18  Show Profile  Reply with Quote
quote:
HAVING indicator id = 1 AND dhb name = 'canterbury dhb ' AND practicename = 'canterbury community pho- 585342'


it should be Indicatorid and DHBName is it ?

"I get a syntax error"
What is the error message ?



KH

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30102 Posts

Posted - 08/22/2006 :  00:54:27  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Also put these comparisons at WHERE, not HAVING.

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Lumbago
Norsk Yak Master

Norway
3271 Posts

Posted - 08/22/2006 :  08:55:14  Show Profile  Reply with Quote
As Peso is saying you need to use the WHERE-statement instead. HAVING is like the WHERE but for the aggregated columns instead. Example:

SELECT Indicatorid, DHBName, PHOName, PracticeName, SUM(Numerator) AS Expr1, SUM(Denominator) AS Expr2
FROM PhoNew
WHERE Indicatorid = 1 AND DHBName = 'canterbury dhb ' AND practicename = 'canterbury community pho- 585342'
GROUP BY Indicatorid, DHBName, PHOName, PracticeName
HAVING SUM(Numerator) > 52 AND SUM(Denominator) < 4

--
Lumbago
"Real programmers don't document, if it was hard to write it should be hard to understand"
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.25 seconds. Powered By: Snitz Forums 2000