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
 General SQL Server Forums
 New to SQL Server Programming
 Month and Year Between

Author  Topic 

asif372
Posting Yak Master

100 Posts

Posted - 2013-06-26 : 03:14:04
hellow,
i want dta to search like this

search
from
TABLE
Where
YEAR (DATE) between 2012 and 2013
AND
MONTH (DATE) BETWEEN 5 AND 1

but it didnot give the required result
kindly suggest...

mmkrishna1919
Yak Posting Veteran

95 Posts

Posted - 2013-06-26 : 03:25:40
While using BETWEEN clause you should take care about range values

BETWEEN 1 and 5 will give results.
it will convert to month(date)>=1 and month(date)<=5

Read this for better understanding:
http://sqlblog.com/blogs/john_paul_cook/archive/2013/04/27/problems-using-between.aspx

Thanks..

M.MURALI kRISHNA
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-26 : 03:27:14
i prefer this method


search
from
TABLE
WHERE DATE >='20120501'
AND DATE < '20130201'


see reason here

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

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -