Click here to Skip to main content
15,897,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
id mark1 mark2 mark3
1 85 85 89
2 78 78 98
3 67 67 75
4 79 79 76
5 76 76 83

I have the above table called marks. I've written the following query.

SQL
SELECT ID, CASE MARK1
WHEN mark1 > 85 THEN (MARK1*2)
ELSE MARK1
END
"NEW MARK1"
FROM marks



If mark 1 > 70 i want to multiply tat data by 2. but when i run tat query i m getting the following error.

Incorrect syntax near '>'. what's wrong with tat query?
Posted

Use it like this..

SQL
SELECT ID, CASE WHEN mark1 > 85 THEN (MARK1 * 2)
ELSE MARK1 END [NEW MARK1]
FROM marks
 
Share this answer
 
v2
Comments
ARUN K P 12-Aug-13 7:23am    
Thanks adarsh.
+5
Adarsh chauhan 12-Aug-13 7:25am    
well you forgot to click +5 :)
ARUN K P 12-Aug-13 7:26am    
how to click +5. ??
i m just typing +5 and entering.
Stephen Hewison 12-Aug-13 7:28am    
Click the stars on the top right of the solution
ARUN K P 12-Aug-13 7:30am    
Ok done stephen thanks :)
You're using the case statement in two ways at the same time

If testing for a specific value you can:

SQL
CASE MARK1 WHEN 10 THEN doThis ELSE doThat END


Or you can have multiple types of test like this:

SQL
CASE WHEN MARK1 > 10 THEN doThis ELSE doThat END


What you've written is a bit of a mash up between the two.
 
Share this answer
 
Comments
ARUN K P 12-Aug-13 7:24am    
ok thanks stephen
Adarsh chauhan 12-Aug-13 7:24am    
nice explanation... +5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900