Click here to Skip to main content
15,888,239 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
SQL
select @return=
case @per
when @per>80 then 5
when @per>60 then 4
when @per>40 then 3
when @per>20 then 1
else 0
end



what is the correct query for this condition?
this is not working for me.plz help.....

SQL
now this query returns this error:
Msg 102, Level 15, State 1, Procedure Findpoints, Line 10
Incorrect syntax near '>'.
Msg 102, Level 15, State 1, Procedure Findpoints, Line 18
Incorrect syntax near 'end'.
Posted

Hi,

Try this...
SQL
select @return= (case 
when @per>80 then 5
when @per <=80 AND @per>60 then 4
when @per <=60 AND @per>40 then 3
when @per <=40 AND @per>20 then 1
else 0
end)

Regards,
GVPrabu
 
Share this answer
 
Comments
_Amy 23-May-13 4:05am    
+5!
SQL
declare @return int
declare @per int


set @per=25

select @return=(
case
when @per>80 then 5
when @per>60 then 4
when @per>40 then 3
when @per>20 then 1
else 0
end)

select @return



VB
result
-----------
1

(1 row(s) affected)
 
Share this answer
 

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