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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Help with dates equaling dates...please!

Author  Topic 

brendalisalowe
Constraint Violating Yak Guru

269 Posts

Posted - 2005-03-24 : 13:57:01
Can anyone tell me why this won't work?

SELECT CaseNumber
FROM tblCapRec
WHERE CONVERT(CHAR(10),mailedfirst,101) = CONVERT(CHAR(10),'3/24/2005',101)

I know the mailedfirst date does equal 3/24/2005. What am I doing wrong with the dates? Thanks!

Brenda

If it weren't for you guys, where would I be?

cshah1
Constraint Violating Yak Guru

347 Posts

Posted - 2005-03-24 : 14:04:21
SELECT CaseNumber
FROM tblCapRec
WHERE CONVERT(CHAR(10),mailedfirst,101) = CONVERT(CHAR(10),'03/24/2005',101)
Go to Top of Page

brendalisalowe
Constraint Violating Yak Guru

269 Posts

Posted - 2005-03-24 : 14:05:35
Well, that was easy. THANKS!

Brenda

If it weren't for you guys, where would I be?
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2005-03-24 : 19:41:48
When you are selecting by date from a table, you should leave the table datetime column as it is, instead of converting it to CHAR to compare. If you convert it to CHAR, it cannot use any index on the column, and it is also more overhead to convert it.

select
CaseNumber
from
tblCapRec
where
-- Select for entire day of 2005/03/24
mailedfirst >= convert(datetime,'2005/03/24') and
mailedfirst < convert(datetime,'2005/03/25')




CODO ERGO SUM
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-03-24 : 23:34:01
Also, consider not storing times at all with your dates -- store it in a separate column. See:

http://weblogs.sqlteam.com/jeffs/archive/2004/12/02/2954.aspx




- Jeff
Go to Top of Page
   

- Advertisement -