shafiqrao
asked on
IF condition in Select Query
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 ?
Try this:
Select *, iif(nz(trim(mydecision))<> "", mydecision, iif(nz(trim(fathersdecisio n))<>"", fathersdecision, grandfathersdecision)) as SuperDecision From table
Select *, iif(nz(trim(mydecision))<>
ASKER
for me
Select *, iif(nz(trim(mydecision))<> "", mydecision, iif(nz(trim(fathersdecisio n))<>"", 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 ?
Select *, iif(nz(trim(mydecision))<>
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 ?
ASKER
it worked, sorry, my own mistake, thanks for co-operation.
You are welcome
ASKER