Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 Other Forums
 MS Access
 Why am I getting Division By Zero Error?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

14 Posts

Posted - 12/13/2012 :  19:12:59  Show Profile  Reply with Quote
Creating a simple recurring Chores database.

EveryNDays 'This is greater than zero if the chore rule applies
EveryNWeeks 'This is 0 if EveryNDays is greater than 0
StartOn 'Date to start

When querying what chores to do for today, out of all the chores that should be done every N days.

I started by:
SELECT ChoreName FROM Chores
WHERE (EveryNDays <> 0) AND
(Now() - StartOn) Mod EveryNDays) = 0

Resulted in Division By zero.

Reading up on (the lack of) operator shortcircuiting in SQL, I changed to:

(SELECT * FROM Chores WHERE EveryNDays <> 0) AS T2
WHERE (Now() - StartOn) Mod EveryNDays) = 0

Same result.

Any thoughts?

*** Edit. I'll add that I'm actually using DateDiff to get the number of days between StartOn and Now, for the sake of clarity, those are omitted.

Edited by - Nexzus on 12/13/2012 19:18:28

Flowing Fount of Yak Knowledge

United Kingdom
3385 Posts

Posted - 12/14/2012 :  05:42:29  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
It's up to the server how it executes the statement. It has probably spotted that your second one is functionally the same as the first and executed in the same manner - annoying that optimsers are getting smarter.

Maybe something like
where iif (EveryNDays=0,1,(Now() - StartOn) Mod EveryNDays) = 0

not sure about syntax in access

Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Starting Member

14 Posts

Posted - 12/17/2012 :  16:57:39  Show Profile  Reply with Quote
Ah, that works. Thanks much.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000