473,387 Members | 1,650 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,387 software developers and data experts.

double if condition in MS access query

21
hey guys,
I want to do some mathwork in a MS access query. But i tried a couple of syntax to get this to work but i can quite get my condition translated for a MS access querry Can someone tell me how i get get two IF conditions into the query.
My psudo-code is as follows
Expand|Select|Wrap|Line Numbers
  1. iF (Priority='AOG')
  2.   if (Service = 'D2D')
  3.     timeA = time2-time1
  4.   else 
  5.     timeA = time3-time1
  6. else
  7.   if (Service = 'D2D')
  8.     timeA = time2-time4
  9.   else 
  10.     timeA = time5-time4
  11.  
Jul 19 '10 #1

✓ answered by NeoPa

Assuming you have all the fields specified available, then you would need to use the IIf() function. In this case it would have to be stacked :
Expand|Select|Wrap|Line Numbers
  1. timeA: IIf([Priority]='AOG',
  2.            IIf([Service]='D2D',[time2]-[time1],[time3]-[time1]),
  3.            IIf([Service]='D2D',[time2]-[time4],[time5]-[time4]))
Welcome to Bytes!

PS. Linq brings up an important point about dealing with dates & times. I cannot guarantee your maths will work. I only duplicate what you already had to illustrate the structure of the instruction.

3 3295
missinglinq
3,532 Expert 2GB
I think that first off we need to know what kind of Datatypes are we dealing with here. Are Time1, Time2, TimeA, etc. actual Date/Time fields, as their names imply, or something else, such as Numbers or Text? If Date/Time fields, do they contain Date and Time or just Time?

Or are these Lapsed Times, i.e. hours, minutes, seconds?

All these things make a difference in how you do 'math' with 'times.'

Welcome to Bytes!

Linq ;0)>
Jul 19 '10 #2
NeoPa
32,556 Expert Mod 16PB
Assuming you have all the fields specified available, then you would need to use the IIf() function. In this case it would have to be stacked :
Expand|Select|Wrap|Line Numbers
  1. timeA: IIf([Priority]='AOG',
  2.            IIf([Service]='D2D',[time2]-[time1],[time3]-[time1]),
  3.            IIf([Service]='D2D',[time2]-[time4],[time5]-[time4]))
Welcome to Bytes!

PS. Linq brings up an important point about dealing with dates & times. I cannot guarantee your maths will work. I only duplicate what you already had to illustrate the structure of the instruction.
Jul 19 '10 #3
dileshw
21
Thanks guys!!!
It worked...the "times" were formatted as date/time... did some minor *24 etc manipulations to get the result int he desired output... the main problem i had was in the double IF conditions :)
Thanks again!!!
Jul 20 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: david liu | last post by:
access 2000 query: here's what i want to do. from an asp page, perform a search on a table in access. i have used sql code in the asp page itself, but i'd rather execute a query in access. i...
5
by: Art | last post by:
Hi, Can anyone point me to an example of how I would execute a query I've created in an Access DB. I've copied the SQL down to my VB.net application and that works fine, but it's ugly. I'd like...
8
by: s_wadhwa | last post by:
SELECT DISTINCTROW "01C" AS dummy, Buildings.BuildingNumber, UCASE(Buildings.BuildingName) AS BuildingName, Buildings.MasterPlanCode, Buildings.UniformBuildingCode,...
4
by: ShastriX | last post by:
Getting a weird error while trying out a query from Access 2003 on a SQL Server 2005 table. Want to compute the amount of leave taken by an emp during the year. Since an emp might be off for...
12
by: zwasdl | last post by:
Hi, I'm using MS Access to query against Oracle DB via ODBC. Is it possible to use HINT in Access? Thanks, Wei
1
by: mrkselm | last post by:
Hi, I am stuck with a problem in MS Access which does not occur in SQL Server and I have been banging my head against the wall for a couple of days now trying to resolve it. Namely, when I...
3
by: =?Utf-8?B?bXNjZXJ0aWZpZWQ=?= | last post by:
Has anyone successfully used an Access query from .NET? I am trying to do this and am getting a weird error. .NET calls queries 'stored procedures'. The error I am getting says "Schema could not be...
2
by: k-man | last post by:
Hi: I have an MS Access query for a table called MyTable. One of my fields in the query is a custom field that looks like "MyField: = MyFunction(ID)" where ID is a field in MyTable. I have...
2
by: rahuldev999 | last post by:
Hi Can anyone please convert the below access query to the equivalent stored procedure.No problem with the IIF() function but the condition in the "where" clause making problem.so please put some...
6
by: jsacrey | last post by:
Hey everybody, got a secnario for ya that I need a bit of help with. Access 97 using linked tables from an SQL Server 2000 machine. I've created a simple query using two tables joined by one...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.