More Complex Calc in Query

M

Michael

Hi Folks - I need some help with a query. Here's the business logic:

If HoursWorked < 4, then HoursWorked = 4
else
If HoursWorked > 4 and <= 6, then HoursWorked = 6
else
If HoursWorked > 6 and <= 8, then HoursWorked = 8
else
If HoursWorked > 8 then HoursWorked = HoursWorked

Should I use an IIF statement, or should I use a public function? Either
way, I'll need some help in creating the IIF statement or setting up the
query to use a public function and the VBA code.

Thoughts?

Thanks.

Mike
 
B

Bob Barrows

Michael said:
Hi Folks - I need some help with a query. Here's the business logic:

If HoursWorked < 4, then HoursWorked = 4
else
If HoursWorked > 4 and <= 6, then HoursWorked = 6

Errr ... what if HoursWorked is exactly 4? I assume you meant:
If HoursWorked <= 4, then HoursWorked = 4

else
If HoursWorked > 6 and <= 8, then HoursWorked = 8
else
If HoursWorked > 8 then HoursWorked = HoursWorked

Should I use an IIF statement, or should I use a public function?

It depends. Here's a nested iif version:
Iif(HoursWorked <= 4,4,Iif(Hoursworked <=
6,6,Iif(HoursWorked<=8,8,HoursWorked)))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top