|
-
Sep 23rd, 2005, 08:44 AM
#1
Thread Starter
Hyperactive Member
Arithmetic overflow[resolved]
Here's one for you guys.
I had this sp.....
Code:
CREATE PROCEDURE spVisitors AS
select convert(varchar,(getdate()-(day(getdate())-1)),101) as startdate, convert(varchar,getdate(),101) as enddate,
sum([count]) as visits, sum(qcount) as requests, pid
from tblcounterv3
where (convert(varchar,cast(countdate as datetime),101) between convert(varchar,(getdate()-(day(getdate())-1)),101)
and convert(varchar,getdate(),101))
group by pid
GO
which worked fine until I set the default language settings on my server from English US to English UK.
Now I get this error :
Server: Msg 8115, Level 16, State 2, Procedure spVisitors, Line 3
Arithmetic overflow error converting expression to data type datetime.
Any ideas?
Last edited by thebloke; Sep 23rd, 2005 at 09:38 AM.
Reason: resolved
The Bloke
www.blokeinthekitchen.com
making cooking cool for blokes
-
Sep 23rd, 2005, 09:04 AM
#2
Re: Arithmetic overflow
Try running that SP's code in query analyzer (minus the create procedure part) and print out what values you are getting for the getdates() and the convert(...,101). Perhaps the switch to the UK format is causing problems in the date time formatting.
-
Sep 23rd, 2005, 09:09 AM
#3
Re: Arithmetic overflow
The only conversion you do to a datetime data type is
Code:
cast(countdate as datetime)
. What format is the countdate column? Try executing this query
Code:
select cast(countdate as datetime) from tblcounterv3
Does it give you the same error?
-
Sep 23rd, 2005, 09:27 AM
#4
Thread Starter
Hyperactive Member
Re: Arithmetic overflow
I did run it in Query Analyser and got the same result. I think the issue is that prior to me changing the settings, the values in the countdate column (which is nvarchar datatype) were being stored as 9/23/2005 however after the change they were going in as 23/09/2005.
I've tried to run
Code:
select cast(countdate as datetime) from tblcounterv3
and get the same error.....
however, I've just tried this
Code:
'using style 103 instead of 101
select convert(datetime,countdate,103) from tblcounterv3
and this returns the date values formatted as 2005-09-23 00:00:00.000
I tried changing all of the 101's in the original sp to 103's but still get the arithmetic overflow error
The Bloke
www.blokeinthekitchen.com
making cooking cool for blokes
-
Sep 23rd, 2005, 09:32 AM
#5
Re: Arithmetic overflow
You only need to change the convert to datetime. Notce that I have replaced the CAST function with CONVERT.
Code:
CREATE PROCEDURE spVisitors AS
select convert(varchar,(getdate()-(day(getdate())-1)),101) as startdate, convert(varchar,getdate(),101) as enddate,
sum([count]) as visits, sum(qcount) as requests, pid
from tblcounterv3
where (convert(varchar,convert(datetime,countdate,103),101) between convert(varchar,(getdate()-(day(getdate())-1)),101)
and convert(varchar,getdate(),101))
group by pid
GO
I really don't understand why you store dates in a varchar column. As you can see it can give you all sorts of problems.
-
Sep 23rd, 2005, 09:33 AM
#6
Thread Starter
Hyperactive Member
Re: Arithmetic overflow
Sussed it:
Code:
select (getdate() - (day(getdate())-1)) as startdate, getdate() as enddate,
sum([count]) as visits, sum(qcount) as requests, pid
from tblcounterv3
where (convert(datetime,countdate,103) between (getdate() - (day(getdate())-1))
and getdate())
group by pid
Thanks guys
The Bloke
www.blokeinthekitchen.com
making cooking cool for blokes
-
Sep 23rd, 2005, 09:37 AM
#7
Re: Arithmetic overflow
 Originally Posted by thebloke
Sussed it:
Code:
select (getdate() - (day(getdate())-1)) as startdate, getdate() as enddate,
sum([count]) as visits, sum(qcount) as requests, pid
from tblcounterv3
where (convert(datetime,countdate,103) between (getdate() - (day(getdate())-1))
and getdate())
group by pid
Thanks guys

So you discovered yourself that you did a lot of uneccessary conversions back and forth between datetime and varchar. Have a nice weekend!
-
Sep 23rd, 2005, 10:31 AM
#8
Thread Starter
Hyperactive Member
Re: Arithmetic overflow[resolved]
Yeah, but they weren't unnecessary when I originally wrote the query, just after I changed the settings!
The Bloke
www.blokeinthekitchen.com
making cooking cool for blokes
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|