SQL Server Performance

Multiple AND in having

Discussion in 'General Developer Questions' started by mita, Aug 21, 2006.

  1. mita New Member

    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
  2. ndinakar Member

    There seems to be a space between Indicator and id in your first where condition.

    ***********************
    Dinakar Nethi
    SQL Server MVP
    ***********************
  3. Roji. P. Thomas New Member

    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
  4. parveen New Member

    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.
  5. chiragkhabaria New Member

    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

Share This Page