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)
 Function returning whole values

Author  Topic 

mxfrail
Yak Posting Veteran

84 Posts

Posted - 2009-09-03 : 11:41:33
[code]
CREATE FUNCTION ASP_MailingValue
(
@ClientID int,
@ProdDate datetime
)
RETURNS decimal
AS
BEGIN
RETURN (
SELECT Sum(tblContractDetail.[BillingFlatFee]+tblContractDetail.[billingrate]*tblContractDetail.[homes]/1000) AS [Value]
FROM (tblContractDetail
INNER JOIN tblContracts ON tblContractDetail.ContractID = tblContracts.ContractID)
WHERE tblContracts.clientid= @ClientID and tblContractDetail.ProdDate = @ProdDate
)
END

[/code]

In the above ... if BillingRate = 25 and BillingFlatFee=0 and Homes=16500 it should be 412.5 but is returning 413.

Any help?

Thanks

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-09-03 : 11:46:05
You need to give the decimal a precision.

So, decimal(6,2) or similar, rather than just decimal.

You also need to ensure your other fields are decimals, you may wannt to ensure this by CASTing or CONVERTing each field.
Go to Top of Page

mxfrail
Yak Posting Veteran

84 Posts

Posted - 2009-09-03 : 11:50:24
Ahh ... perfect.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-04 : 02:15:14
or
http://sqlblogcasts.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
   

- Advertisement -