Connecting Tech Pros Worldwide Forums | Help | Site Map

please solve this problem

Member
 
Join Date: Jun 2007
Posts: 78
#1: Aug 7 '08
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's Avatar
Needs Regular Fix
 
Join Date: Jan 2008
Location: South Africa
Posts: 360
#2: Aug 8 '08

re: please solve this problem


Expand|Select|Wrap|Line Numbers
  1. SELECT user_accountID,Expensives,SUM(quotaAmount) FROM user_accounts WHERE quotaNo = 'quota1' Group by user_accountID
Newbie
 
Join Date: Aug 2008
Posts: 31
#3: Aug 9 '08

re: please solve this problem


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

What do you want to achieve?
Delerna's Avatar
Expert
 
Join Date: Jan 2008
Location: Sydney
Posts: 788
#4: Aug 10 '08

re: please solve this problem


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

This
Expand|Select|Wrap|Line Numbers
  1. SELECT user_accountID,
  2.    CASE when quotaNo = 'quota1' 
  3.    THEN sum(quotaAmount) 
  4.    ELSE 0 end as Expensive
  5. FROM user_accounts
  6. group by user_accountID
  7.  
might be how you meant it but I can't tell.
What BHTanna requests might prove helpfull.
Reply