?
Solved

IF condition in Select Query

Posted on 2004-09-24
7
Medium Priority
?
1,898 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

762 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