Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Request for Query....if-else..!!!

Author  Topic 

cool_moon
Starting Member

26 Posts

Posted - 2003-02-15 : 09:01:42
hi there.....this is my first Request and i hope you genius people will reply me soon.....this is my request,can anybody tell me the query for the following condition......

==========================================

if((Marks>50)&(Marks<100))
then Grade="D"
else
if((Marks>100)&(Marks<200))
then Grade="C"
else
if((Marks>200)&(Marks<300))
then Grade="B"
else
if((Marks>300)&(Marks<400))
then Grade="A"

where Mark and Grade are the field of the table.
==========================================

In the above case when a person get say "255" Marks then he will get "B" grade automatically,so can you please tell me what will be the query for such a condition.I'll be greatful to you.take care God Bless You All.


robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-02-15 : 09:10:36
SELECT CASE WHEN Marks > 300 THEN 'A'
WHEN Marks > 200 THEN 'B'
WHEN Marks > 100 THEN 'C'
WHEN Marks > 50 THEN 'D'
ELSE 'F' END
FROM myTable


You can find out more about the CASE expression in Books Online, or search SQL Team for "CASE".

Go to Top of Page
   

- Advertisement -