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
 Other Forums
 MS Access
 Request for query.....else-if....!!!

Author  Topic 

cool_moon
Starting Member

26 Posts

Posted - 2003-02-16 : 07:48:05
hi there.....can anyone tell me the SQL for the following case......!!!

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

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-16 : 07:50:21
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=23872

Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-02-16 : 10:04:49
Did you accidentally post in the SQL forum, then re-posted in the Access forum because you are using Access? If so, then the CASE expression won't work.

In that case, you can use the IIF() function:

Grade: iif(Marks>300,"A",iif(Marks>200,"B",iif(Marks>100,"C",iif(Marks>50,"D","F"))))


- Jeff
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-02-16 : 10:18:08


I need your eyesight Jeff.

In case (get it? in case? I crack myself up) you don't like to nest iif() calls:

Grade: Switch(Marks>300,"A", Marks>200,"B", Marks>100,"C", Marks>50,"D", True,"F")

Go to Top of Page

cool_moon
Starting Member

26 Posts

Posted - 2003-02-16 : 16:21:30
Oh thank alottt Rob and Jeff,now it's working just fine.I am very Glad for your support.Thank again.take care and God Bless You All.

Go to Top of Page
   

- Advertisement -