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 2008 Forums
 Transact-SQL (2008)
 Decimal for day

Author  Topic 

SMALLMONEY1
Starting Member

2 Posts

Posted - 2010-11-05 : 20:36:53
I am trying to include a calculation in my SP of how many pounds are consumed in a day with the following:

CAST((50/DATEDIFF(day, date1, date2)) AS DECIMAL(8,2)) LbsPerDay

It will not calculate in decimal, only a whole number since it is a day. Is there a way to make it into a decimal?
$50/20 days = 2.5, displays as 2

Sachin.Nand

2937 Posts

Posted - 2010-11-06 : 06:26:21
50*1.0/DATEDIFF(day, date1, date2)

PBUH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-08 : 05:36:16
Here is the reason
http://beyondrelational.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SMALLMONEY1
Starting Member

2 Posts

Posted - 2010-11-08 : 14:33:45
Thank You! for the fix and the explanation. I have been going crazy trying to figure that out.
Go to Top of Page
   

- Advertisement -