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.
Author |
Topic |
Dale
Starting Member
1 Post |
Posted - 2004-08-09 : 13:45:57
|
Hi,Could someone please HELP me?I am running the following query in an ASP page to pull records from an Access db:"SELECT * FROM table WHERE Month(Date) = DatePart('m',Now())+1"Which returns all records for the next month, if I use:"SELECT * FROM table WHERE Month(Date) = DatePart('m',Now())+2"it returns the records 2 months from now, this is fine up till I get to December, when I try to return records from say January 2005 by adding +5 (assuming its August now)it returns no records at all.As anyone got the answer to where I am going wrong?? |
|
timmy
Master Smack Fu Yak Hacker
1242 Posts |
Posted - 2004-08-09 : 19:22:56
|
The query you're using only uses the month, not the month/year which would be causing problems. Especially when you go over into a new year. You're query would be looking for month 13, which would obviously cause problems.I would prefer the following:WHERE Date BETWEEN '1-Jan-2005' and '31-Jan-2005 23:59:59' |
 |
|
Sam Freeman
Starting Member
8 Posts |
Posted - 2004-08-09 : 19:35:57
|
when I run that against a table that has no records for next month, but does have records for that month last year, it pulls last year's records. I assume that is because the Month(Date) does not provide a specific year as a criteria.Try this (it worked for me):SELECT *FROM tableWHERE (((Month([Date]))=Month(Now())+2) AND ((Year([Date]))=Year(Now()))); |
 |
|
|
|
|