Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
mitasid
Yak Posting Veteran
51 Posts |
Posted - 2006-08-21 : 23:47:56
|
Hi GuysI 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 Expr2FROM PhoNewGROUP BY Indicatorid, DHBName, PHOName, PracticeNameHAVING 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 errorPlease helpThanksMita |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-08-21 : 23:56:18
|
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 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-22 : 00:54:27
|
Also put these comparisons at WHERE, not HAVING.Peter LarssonHelsingborg, Sweden |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2006-08-22 : 08:55:14
|
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 Expr2FROM PhoNewWHERE Indicatorid = 1 AND DHBName = 'canterbury dhb ' AND practicename = 'canterbury community pho- 585342'GROUP BY Indicatorid, DHBName, PHOName, PracticeNameHAVING 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" |
|
|
|
|
|
|
|