| Author |
Topic |
|
D Martin
Starting Member
2 Posts |
Posted - 2002-11-27 : 12:18:02
|
| I'm trying to write a simple query with a specific date criteria.EX. Select * From Logs where date='11/26/02'I've like using Like, IN, and others but nothing seems to work other than using relational operators and Between. Is there a problem with datatype DateTime? Is there a way to do this query? |
|
|
VyasKN
SQL Server MVP & SQLTeam MVY
313 Posts |
Posted - 2002-11-27 : 12:23:19
|
| You need to include time also in your WHERE clause. For example:Select * From Logs where date between '11/26/02 00:00' and '11/26/02 23:59'--HTH,Vyashttp://vyaskn.tripod.com |
 |
|
|
D Martin
Starting Member
2 Posts |
Posted - 2002-11-27 : 12:25:18
|
| So the only way to query for a specific date is using between? |
 |
|
|
Arnold Fribble
Yak-finder General
1961 Posts |
Posted - 2002-11-27 : 12:28:33
|
| The only way to query for a specific date is not using between.DECLARE @dt datetimeSET @dt = '20021126'SELECT * FROM Logs WHERE date >= @dt AND date < DATEADD(d, 1, @dt) |
 |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
Posted - 2002-11-28 : 00:44:58
|
| Arnold are you saying that the between method does not work.If so why does the between not work?Also would your other method be faster?SELECT * FROM Logs WHERE dateadd(dd,datediff(dd,0,date),0) = @dtEdited by - ValterBorges on 11/28/2002 00:49:50 |
 |
|
|
mdanwerali
Starting Member
30 Posts |
Posted - 2002-11-28 : 02:49:25
|
| HiInstead of Between and Dateadd we can use Convert function which is very easy to use. what do u say.Select * From Logs where date = convert(char,'01/03/03')Md Anwer Ali |
 |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2002-11-28 : 03:36:43
|
quote: HiInstead of Between and Dateadd we can use Convert function which is very easy to use. what do u say.
Not wanting to preempt him, but I'm guessing he'll say that the other way is faster.-------Moo. |
 |
|
|
simondeutsch
Aged Yak Warrior
547 Posts |
Posted - 2002-11-28 : 15:35:02
|
Syntax for Convert:CONVERT (data_type[(length)], expression [, style])so it would be CONVERT(char(10),date,101) for '01/01/2003'But I have a recollection of someone posting that CONVERT is slower than using BETWEEN, or s/t like that. It's slower than some other solution, which I don't remember what that is. Sarah Berger MCSD |
 |
|
|
simondeutsch
Aged Yak Warrior
547 Posts |
Posted - 2002-11-28 : 15:40:39
|
Syntax for Convert:CONVERT (data_type[(length)], expression [, style])so it would be CONVERT(char(10),date,101) for '01/01/2003'But I have a recollection of someone posting that CONVERT is slower than using BETWEEN, or s/t like that. It's slower than some other solution, which I don't remember what that is. Sarah Berger MCSD |
 |
|
|
|