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
There seems to be a space between Indicator and id in your first where condition. *********************** Dinakar Nethi SQL Server MVP ***********************
You dont really need to put those conditions in the HAVING Clause. You can fileter them out with the WHERE Clause. Roji. P. Thomas Microsoft SQL Server MVP http://toponewithties.blogspot.com
Yes, Removing the spaces, It works for me... And you can use where clause there. Don't take life so seriously, you will never get out of it alive.
Try this SELECT Indicatorid, DHBName, PHOName, PracticeName, SUM(Numerator) AS Expr1, SUM(Denominator) AS Expr2 FROM PhoNew Where indicator id = 1 AND RTrim(LTrim([dhb name])) = LTrim(RTrim('canterbury dhb ')) AND LTRim(RTrim(practicename)) = 'canterbury community pho- 585342' GROUP BY Indicatorid, DHBName, PHOName, PracticeName Chirag