Solved

IF condition in Select Query

Posted on 2004-09-24
7
1,884 Views
Last Modified: 2008-02-01
I have a table like this

SerialNumber    MyDecision    FathersDecision       GrandFatherDecesion
-----------------------------------------------------------------------------------
1                                                                       GoToSchool
2                                             GoToNeighbors    GoToColony
3                      GoToFriends     GoToPeople         GoToAll
4                                              EatEnough          EatWell

I want to make a query that selects all of the above 4 fields as they are right now and i want to add another field that id called as SuperDecesion, it should have MyDecesion, if it is blank then, FathersDecision, if FathersDecision is also null then it should contain GrandFatherDecesion, in short the 5thcolumn should look like this in the aboce specific example

SuperDecesion
-----------------
GoToSchool
GoToNeighbors
GoToFeiends
EatEnough

can some one make exact query, i know it will have IF condition in query but i failed to make it. Please help ASAP.
0
Comment
Question by:shafiqrao
  • 4
  • 3
7 Comments
 
LVL 16

Accepted Solution

by:
Nestorio earned 101 total points
ID: 12146528
Try:

Select *, Nz(MyDecision, Nz(FathersDecision,GrandFathersDecision)) as SuperDecision From table
0
 

Author Comment

by:shafiqrao
ID: 12146635
worked great, thanks.
0
 

Author Comment

by:shafiqrao
ID: 12146723
how to trim the blank spaces, i have fileds that have data like '    ' this is not treated as NULL so what should i modify in the query ?
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 16

Expert Comment

by:Nestorio
ID: 12146845
Try this:
Select *, iif(nz(trim(mydecision))<>"", mydecision, iif(nz(trim(fathersdecision))<>"", fathersdecision, grandfathersdecision)) as SuperDecision From table
0
 

Author Comment

by:shafiqrao
ID: 12146963
for me

Select *, iif(nz(trim(mydecision))<>"", mydecision, iif(nz(trim(fathersdecision))<>"", fathersdecision, grandfathersdecision)) as SuperDecision From table
 
this is not working, but if you eliminate {as SuperDecision} from the query then it works fine and names the field as Expr1000, if i donot eliminate it then it asks me value of SuperDecision.Expr1000

is it working with you ?
0
 

Author Comment

by:shafiqrao
ID: 12146984
it worked, sorry, my own mistake, thanks for co-operation.
0
 
LVL 16

Expert Comment

by:Nestorio
ID: 12147048
You are welcome
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now