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 2005 Forums
 Transact-SQL (2005)
 What data type to use for a decimal

Author  Topic 

theboyholty
Posting Yak Master

226 Posts

Posted - 2009-03-18 : 11:08:58
I'm trying to do an average on a set of data. There's 43 records and the numbers total 75. My SQL Query is basically:

AVG(DATEDIFF(d,wfa.actiondate,ac.ActionDate))

When I cast this is either decimal, real or int I get the result 1 (it should be 1.74) and even when I cast as money I get 1.00.

I'm clearly doing something fundamentally stupid - irs hardly rocket science, so please will someone point out the bleeding obvious to me.

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-03-18 : 11:15:38
Try this..

CAST(AVG(CAST(DATEDIFF(d,wfa.actiondate,ac.ActionDate) AS DECIMAL (10,2)) AS DECIMAL (10,2)
Go to Top of Page

theboyholty
Posting Yak Master

226 Posts

Posted - 2009-03-18 : 11:19:14
That's the one. Cheers bud.
Go to Top of Page
   

- Advertisement -