Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculation within SQL 1

Status
Not open for further replies.

neemi

Programmer
May 14, 2002
519
GB
SQL SERVER 2005

SQL used within ADO but tested in query ananylser.

I have a calculation with a SQL Statement and the number I am being presented with is incorrect in the sense that I should get the result 8.2 but am being returned with 8.

I need to round the values up so that the actual 8.2 I should get I want as 9.

The calculation is for example

(X-Y+Z)/7

the values I have as an example are:

x=88
Y=60
z=30

therefore
(88-60+30)/7 = 8.29

but the result i am being returned with is

(88-60+30)/7 = 8

WHY IS IT BEING ROUNDED DOWN?
HOW CAN I GET THE ACTUAL VALUE?
SO I CAN ROUND UP?

Please help>
Cheers,
Neemi
 
Because all values you used are integers the returning result is also integer.
Try:
Code:
SELECT 1.0*(X-Y+Z)/7

or
Code:
SELECT (X-Y+Z)/7.0


Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Thanks. That works like a dream!!!

One more question.... If th number has a decimal... how do I round up?

ie. 8.2 = 9
 
Code:
SELECT CEILING(1.0*(X-Y+Z)/7) AS Test

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
GOT IT! Used Ceiling!!!! whoo hoo!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top