please solve this problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phanimadhav
    New Member
    • Jun 2007
    • 78

    please solve this problem

    Hi friends this is my select statement

    SELECT user_accountID, Expensive = case quotaAmount
    when quotaNo = 'quota1' then sum(quotaAmount ) else 0 end
    FROM user_accounts

    Msg 102, Level 15, State 1, Line 2
    Incorrect syntax near '='.

    whenever i am executing the query this error will be occur please clear this error
    i am newone of this sqlserver.I did not understand this problem.Please clarify my doubt
  • OuTCasT
    Contributor
    • Jan 2008
    • 374

    #2
    [CODE=sql]SELECT user_accountID, Expensives,SUM( quotaAmount) FROM user_accounts WHERE quotaNo = 'quota1' Group by user_accountID[/CODE]

    Comment

    • BHTanna
      New Member
      • Aug 2008
      • 31

      #3
      Can you just tell, what are you exactly trying do?

      What do you want to achieve?

      Comment

      • Delerna
        Recognized Expert Top Contributor
        • Jan 2008
        • 1134

        #4
        You are getting the error because you have the syntax of the case statement wrong

        This
        [code=sql]
        SELECT user_accountID,
        CASE when quotaNo = 'quota1'
        THEN sum(quotaAmount )
        ELSE 0 end as Expensive
        FROM user_accounts
        group by user_accountID
        [/code]

        might be how you meant it but I can't tell.
        What BHTanna requests might prove helpfull.

        Comment

        Working...