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
 General SQL Server Forums
 New to SQL Server Programming
 Month and Year Between
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

asif372
Posting Yak Master

Pakistan
100 Posts

Posted - 06/26/2013 :  03:14:04  Show Profile  Reply with Quote
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

India
95 Posts

Posted - 06/26/2013 :  03:25:40  Show Profile  Reply with Quote
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

Edited by - mmkrishna1919 on 06/26/2013 03:27:20
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 06/26/2013 :  03:27:14  Show Profile  Reply with Quote
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
  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.03 seconds. Powered By: Snitz Forums 2000