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 |
|
want_to_know
Starting Member
13 Posts |
Posted - 2008-04-07 : 16:43:20
|
| Hi,I need help. I want to select dates less than 15 months, as i am new to sql server , can anyone advise me.I tried this query but it gave me the dates that are greater than 15 monthsSelec calendardate from table where calendardate < getdate()-457Thanks |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-04-07 : 16:46:36
|
| Select calendardate from table where datediff(month,Yourdatecolumn,Getdate())<15 |
 |
|
|
want_to_know
Starting Member
13 Posts |
Posted - 2008-04-07 : 16:50:45
|
Thank yo sodeepIt workedGod bless youquote: Originally posted by sodeep Select calendardate from table where datediff(month,Yourdatecolumn,Getdate())<15
|
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2008-04-07 : 17:25:05
|
quote: Originally posted by sodeep Select calendardate from table where datediff(month,Yourdatecolumn,Getdate())<15
This is a better way to do these types of queries, because it does not require SQL Server to run every row through a function, and it allows it to use indexes on the datatime column.Select calendardate from table where Yourdatecolumn >= dateadd(month,datediff(month,0,getdate())-15,0) CODO ERGO SUM |
 |
|
|
|
|
|
|
|