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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Thoughts on the purpose of...
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

duhaas
Constraint Violating Yak Guru

310 Posts

Posted - 03/11/2013 :  13:48:24  Show Profile  Reply with Quote
Trying to translate what a prior employee was doing and have the following:

Where DATEADD(dd, 0, DATEDIFF(dd, 0, PRODDATE)) BETWEEN '02/02/2012' AND '03/03/2013' 
AND 
ORDEREDCOPIES > 0


From what I can tell, the dateadd/datediff isn't actually doing anything. Was just hoping to get a sanity check.

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 03/11/2013 :  14:00:52  Show Profile  Reply with Quote
it should have been this


Where DATEADD(dd, DATEDIFF(dd, 0, PRODDATE),0) BETWEEN '02/02/2012' AND '03/03/2013' 
AND 
ORDEREDCOPIES > 0


but a much better way is this


Where PRODDATE >= '2012-02-02' AND PRODDATE < '2013-03-04' 
AND 
ORDEREDCOPIES > 0


see

http://visakhm.blogspot.in/2012/12/different-ways-to-implement-date-range.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

duhaas
Constraint Violating Yak Guru

310 Posts

Posted - 03/11/2013 :  14:08:14  Show Profile  Reply with Quote
GREAT, thanks for the feedback, appreciate it as always
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 03/11/2013 :  14:12:32  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

ScottPletcher
Constraint Violating Yak Guru

USA
340 Posts

Posted - 03/11/2013 :  19:18:06  Show Profile  Reply with Quote
To be safe, it should actually be this:

Where PRODDATE >= '20120202' AND PRODDATE < '20130304'
AND
ORDEREDCOPIES > 0
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.05 seconds. Powered By: Snitz Forums 2000