473,382 Members | 1,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

If then Else in Query

I am having a hard time doing the following in a query.

I need my field "EarnedValue" to return the result depending on other
fields.

The code in VB would look like this:

If [sumofhrs] > 0 and [Complete] = false then
[earnedvalue] = [sumofbudget] *.5
elseif [complete]= true then
[earnedvalue] = [sumofbudget]
else
[earnedvalue] = 0
Endif

I need to get this EarnedValue returned on the query since I need to
use this calculation on a report.
Can this be done.
If I need to call it as a function then I will need even more help
(never done that)
thanks
KO

Nov 13 '05 #1
2 30031
pks
In queries the syntax is:
iif({condition to evaluate},{value if condition is true},{value if
condition is false})

Note that the braces are not used; I only included them for emphasis.
IIf functions (yes, that's 2 "I"'s) can also be nested. Your entry in
the query grid would be:

EarnedValue: iif([sumofhrs] > 0 and [complete] = false,[sumofbudget] *
0.5, iif([complete] = true, [sumofbudget],0))

You can also show this as currency by using the Format function:
EarnedValue: format(iif([sumofhrs] > 0 and [complete] =
false,[sumofbudget] * 0.5, iif([complete] = true,
[sumofbudget],0)),"currency")

Nov 13 '05 #2
On 20 Apr 2005 13:06:31 -0700, turtle wrote:
I am having a hard time doing the following in a query.

I need my field "EarnedValue" to return the result depending on other
fields.

The code in VB would look like this:

If [sumofhrs] > 0 and [Complete] = false then
[earnedvalue] = [sumofbudget] *.5
elseif [complete]= true then
[earnedvalue] = [sumofbudget]
else
[earnedvalue] = 0
Endif

I need to get this EarnedValue returned on the query since I need to
use this calculation on a report.
Can this be done.
If I need to call it as a function then I will need even more help
(never done that)
thanks
KO


You can use nested IIf() statements.

Add a new column to the query grid.

EarnedValue:IIf([sumofhrs] > 0 and [Complete] = false,[sumofbudget]
*.5,IIf([complete]= true,[sumofbudget],0))

--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris | last post by:
Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again...
1
by: George | last post by:
Hi, I'm trying to run a select statement that takes includes an if/else clause. I need to select the 'tran_date' between.... if the current month is greater than 10 i.e. after OCT then the...
6
by: Karen Middleton | last post by:
In MS Access I can do in one SQL statement a update if exists else a insert. Assuming my source staging table is called - SOURCE and my target table is called - DEST and both of them have the...
8
by: Carl | last post by:
Hi, Using MS Access 2000, is it possible to run a UPDATE or INSERT SQL query using some form of conditional IF THEN ?? for example: SELECT * FROM Books IF EXISTS(Select Books.ID = 1)
2
by: naughtybynature | last post by:
<html> <head> <title>Search Questions</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php $query = '';
1
by: naughtybynature | last post by:
<html> <head> <title>Search Questions</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php $query = '';
3
by: dannymac83 | last post by:
I have been teaching myself access and VBA for the past week and am extraordinarily confused. I have a table full of employee data, including social security numbers. I want to search the table for...
2
by: paulw4 | last post by:
Need some help here... I am working in Access and have a query that gets selection criteria from a form with 6 selection options. I also want to be able to check for "all: in any of the 6 combo...
4
by: lutzkac | last post by:
Hi Everyone, I am in a bit of a pickle and need some expert advice. I have a db in access. I am trying to create a query with fields from the tables. In my query I need to take the value of one...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.