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 |
|
vohyndra
Starting Member
7 Posts |
Posted - 2006-12-20 : 00:56:09
|
| hello there.i have a databse with a datetime Filed and i want to find all records of the month on the datetie filed.how can i do it.i was using this but it does not workSELECT * FROM laconexion.lc_members WHERE (baja = MONTH(GETDATE()))thanks a lot |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2006-12-20 : 01:05:14
|
SELECT * FROM laconexion.lc_members WHERE (YEAR(baja) = YEAR(GETDATE()) AND MONTH(baja) = MONTH(GETDATE()))Duane. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-12-20 : 03:39:48
|
| <<SELECT * FROM laconexion.lc_members WHERE (baja = MONTH(GETDATE()))>>1 The datecolumn doesnt have only month value2 Also refer www.sql-server-performance.com/fk_datetime.aspMadhivananFailing to plan is Planning to fail |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-12-20 : 04:06:52
|
| SELECT * FROM laconexion.lc_members WHERE DATEDIFF(month, baja, GETDATE()) = 0SELECT * FROM laconexion.lc_membersWHERE baja >= DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0) and baja < DATEADD(month, DATEDIFF(month, 0, GETDATE()), 31)Peter LarssonHelsingborg, Sweden |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-12-20 : 05:21:39
|
| I prefer using second method as it makes use of index if anyMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|