Where then Else? formula

jarett

Board Regular
Joined
Apr 12, 2021
Messages
175
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a "WHERE" statement in my last query

SQL:
WHERE (((CDate([DateCreated] & " " & [Order Time]))>DMax("dtmQueryLastRun","tblQueryLastRun")));

I need to add another parameter if the (CDate([DateCreated] & " " & [Order Time]) is < DMAX.... then WHERE (((CDate([NEWDATEFIELD])>DMax("dtmQueryLastRun","tblQueryLastRun")))

Can I add this to the same SQL or do I need to add another query?
 
I've never seen the 'if true' and 'if false' parts of IIF contain operators such as >. The basics of IIF is 'do this test'. If True, return this, else return that. You're tests (>) in the 'if true' and 'if false' parts will probably return True or False as criteria, which would never work. Also, why is your data split in to date and time? Now you have to string it together then convert to date/time when you could just store Now() in the table. If you must use these comparison operators in the True False portions, you'll probably have to nest IIFs, in which case this will get very ugly. Maybe a db copy would help those trying to help. Too bad it's not allowed here like it is just about everywhere else.
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
This worked
SQL:
WHERE IIF(CDate([DateCreated] & " " & [Order Time])>DMax("dtmQueryLastRun","tblQueryLastRun"), CDate([DateCreated] & " " & [Order Time])>DMax("dtmQueryLastRun","tblQueryLastRun") , CDate([DateUpdated] & " "  &[Update Order Time])>DMax("dtmQueryLastRun","tblQueryLastRun"))

NEWDATEFIELD=[DateUpdated] & " " &[Update Order Time], will just have to watch to see if there are any inconsistencies.
 
Upvote 0

Forum statistics

Threads
1,221,537
Messages
6,160,401
Members
451,645
Latest member
hglymph

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top