double if condition in MS access query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dileshw
    New Member
    • Oct 2009
    • 21

    double if condition in MS access query

    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
    Code:
    iF (Priority='AOG')
      if (Service = 'D2D')
    	timeA = time2-time1
      else 
    	timeA = time3-time1
    else
      if (Service = 'D2D')
    	timeA = time2-time4
      else 
    	timeA = time5-time4
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    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)>

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32656

      #3
      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 :
      Code:
      timeA: IIf([Priority]='AOG',
                 IIf([Service]='D2D',[time2]-[time1],[time3]-[time1]),
                 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.

      Comment

      • dileshw
        New Member
        • Oct 2009
        • 21

        #4
        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!!!

        Comment

        Working...