?
Solved

IF condition in Select Query

Posted on 2004-09-24
7
Medium Priority
?
1,905 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 404 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

862 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