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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Thoughts on the purpose of...

Author  Topic 

duhaas
Constraint Violating Yak Guru

310 Posts

Posted - 2013-03-11 : 13:48:24
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

52326 Posts

Posted - 2013-03-11 : 14:00:52
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 - 2013-03-11 : 14:08:14
GREAT, thanks for the feedback, appreciate it as always
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-11 : 14:12:32
welcome

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

Go to Top of Page

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2013-03-11 : 19:18:06
To be safe, it should actually be this:

Where PRODDATE >= '20120202' AND PRODDATE < '20130304'
AND
ORDEREDCOPIES > 0
Go to Top of Page
   

- Advertisement -