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
 Transact-SQL (2000)
 Count between Dates...

Author  Topic 

mikebird
Aged Yak Warrior

529 Posts

Posted - 2009-09-09 : 10:15:37
select count(*)
from vrCallLogger
where CallDate between '2009-08-01' and '2009-08-31'

gives error:

Msg 296, Level 16, State 3, Line 2
The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value.


(0 row(s) affected)


How do I do the casting? Tried casting the date strings and then CallDate - niether worked

mikebird
Aged Yak Warrior

529 Posts

Posted - 2009-09-09 : 10:18:15
This format seems to be '01-08-2009' and I forgot the date format is open for change. Decided upon by the builder...
Go to Top of Page

Ifor
Aged Yak Warrior

700 Posts

Posted - 2009-09-09 : 10:52:33
The format yyyymmdd will always work regardless of the date settings on the server.

ps If your CallDate contains times your WHERE clause should probably be:

WHERE CallDate >= '20090801'
AND CallDate < '2009001'
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-09-10 : 00:11:52
Hi use this format,

select count(*)
from vrCallLogger
where CallDate between '8/1/2009'and '8/31/2009'
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-09-10 : 00:18:18
it is better to use ISO format YYYYMMDD as sugggested by Ifor. It does not depend on date format or locale


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -