SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

Nexzus
Starting Member

13 Posts

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

ChoreName
EveryNDays 'This is greater than zero if the chore rule applies
EveryNWeeks 'This is 0 if EveryNDays is greater than 0
'...
'Someothers
'...
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 ChoreName FROM
(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

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3355 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

Nexzus
Starting Member

13 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  
 New 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.07 seconds. Powered By: Snitz Forums 2000