Solved

Database Function Formula

Posted on 2007-04-09
1
220 Views
Last Modified: 2010-06-21
Hi There,

I've been staring at this for some time and I can't figure out why I'm getting 0.000 for an answer.

I've tested my other code in my function and they are working great, it's just when I try to calculate my rating, it keeps returning 0.00.

I've gotten 578 for @TotalAttended and 2 for @TotalAcceptedRefunds, using the formula below, I should be getting back: 0.9965

PRINT @TotalAttended
PRINT @TotalAcceptedRefunds

/* Return 0, if there are no participants that have attended the course */
IF @TotalAttended > 0
     SET @Rating =  (@TotalAttended - @TotalAcceptedRefunds)/@TotalAttended
      
PRINT @Rating

Anyone got an idea, what is wrong with my formula?
0
Comment
Question by:quanmac
1 Comment
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 18878726
please try this:
IF @TotalAttended > 0
     SET @Rating =  cast(@TotalAttended - @TotalAcceptedRefunds as decimal(10,4))/cast(@TotalAttended as decimal(10,4))
     
PRINT @Rating
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now