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
 General SQL Server Forums
 New to SQL Server Programming
 ROUND function in ms-sql server

Author  Topic 

sponguru_dba
Yak Posting Veteran

93 Posts

Posted - 2006-06-13 : 02:36:04
Hi all

if i run
SELECT ROUND(700/1224) -- from sql server queyr analysier iam getting value as "0"

but same query i run in Oracle

SELECT ROUND(700/1224) FROM DUAL; iam getting value ".571895425"

what is reason can some body explan me

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2006-06-13 : 03:11:28
integer division will give you the nearest whole number,also specify a length

SELECT ROUND(700.0/1224,<length>)

--------------------
keeping it simple...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-13 : 04:03:41
Read about Round Functions in sql server help file for more details

Madhivanan

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

smarthya
Starting Member

1 Post

Posted - 2007-02-07 : 01:28:47
Hi All
USING BELOW SQL STATEMENT , WE CAN OVER COME WITH THE ABOVE DECIMAL PROBLEM

SELECT CONVERT(FLOAT,700)/CONVERT(FLOAT,1224)
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-07 : 01:42:27
quote:
Originally posted by sponguru_dba

if i run
SELECT ROUND(700/1224) -- from sql server queyr analysier iam getting value as "0"
You can't run that code in T-SQL. It gives you an syntax error
Msg 189, Level 15, State 1, Line 1
The round function requires 2 to 3 arguments.

Use SELECT ROUND(1.0 * 700/1224, 4) instead.
Or SELECT ROUND(1.0 * colA/colB, 4) FROM YourTable.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -