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 |
|
nemohm
Yak Posting Veteran
69 Posts |
Posted - 2003-12-04 : 13:56:24
|
| Hi,What could be the correct query to search on date with LIKE?There are results I have:SELECT COUNT(*)FROM VIEWEVENTWHERE DateTime like '%2003%'24264SELECT COUNT(*)FROM VIEWEVENTWHERE DateTime like '%2003-12-03%'0select count(*) from viewEVENTwhere DateTime between '2003-12-02 23:59:59' AND '2003-12-03 23:59:59'1879Please help!Thx,Dobby |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-12-04 : 14:00:38
|
| Use DATEPART instead of LIKE. SELECT COUNT(*)FROM VIEWEVENTWHERE DATEPART(yy, DateTime) = 2003SELECT COUNT(*)FROM VIEWEVENTWHERE DATEPART(yy, DateTime) = 2003 AND DATEPART(m, DateTime) = 12 AND DATEPART(d, DateTime) = 3Tara |
 |
|
|
nemohm
Yak Posting Veteran
69 Posts |
Posted - 2003-12-04 : 14:14:50
|
| Tara,Something as DATEPART(yyyy, mm, dd, datetime)?(2003-12-03)Dobby |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-12-04 : 14:17:08
|
| You can not pass more than one thing to DATEPART. Please look up DATEPART in BOL. My second query shows what to do for year, month, and day.Tara |
 |
|
|
nemohm
Yak Posting Veteran
69 Posts |
Posted - 2003-12-04 : 14:31:04
|
| Disregard my last question, please.Thank you very much!Dobby |
 |
|
|
|
|
|