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
 General SQL Server Forums
 New to SQL Server Programming
 how to cast overflow ~ null value eliminated

Author  Topic 

rudba
Constraint Violating Yak Guru

415 Posts

Posted - 2009-03-23 : 16:43:20

i try to cast but get error, how to check null or overflow.
normaly i have data on col0 and col1 like this:
col0=2009-03-23 00:00:00.000
col1=2009-03-23 23:59:59.999


case when [col0] = 0 then 0 else cast(col1*3600/cast([col0] as decimal(10,2)) as decimal(10,2)) end


Msg 8115, Level 16, State 2, Line 17
Arithmetic overflow error converting expression to data type int.
Warning: Null value is eliminated by an aggregate or other SET operation.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-03-23 : 17:08:43
Try 3600.0.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2009-03-23 : 17:11:29
case when [col0] IS NULL THEN 0 WHEN [col0] = 0 then 0 else cast(col1*3600/cast([col0] as decimal(10,2)) as decimal(10,2)) end

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2009-03-23 : 17:12:24
and you could convert the 3600 to decimal Convert(decimal(10,2), 3600) as Tara said.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

rudba
Constraint Violating Yak Guru

415 Posts

Posted - 2009-03-23 : 17:23:42
thanks.
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2009-03-23 : 22:04:14
I am afraid that your query makes no sense to me.

You appear to be multiplying a datetime in col1 by 3600 and then dividing by a datetime in col2???

What exactly are you trying to calculate?




CODO ERGO SUM
Go to Top of Page
   

- Advertisement -