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 the values in particular column

Author  Topic 

vidhya
Posting Yak Master

108 Posts

Posted - 2008-07-16 : 06:49:27
hi friends,

select [Geo Code], [Bell Rating],[Boatyard Rating], Sunset from rpm_Acc where MarinaNo = 2780
This is my code .Its displays the values as
[Geo Code], [Bell Rating],[Boatyard Rating], Sunset
40.099998 1 1 0
but i need to the display the values as
40 1 1 0

I need query to display the above result.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-16 : 06:50:48
use ROUND([Geo Code],0)
Go to Top of Page

vidhya
Posting Yak Master

108 Posts

Posted - 2008-07-16 : 06:57:51
i tried but i never get. when i use select floor(40.12). i m getting the result 40. But i not able to get the result when i use this query " select floor([Geo Code]), [Bell Rating],[Boatyard Rating], Sunset from rpm_Acc where MarinaNo = 2780"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-16 : 07:26:00
What is the datatype of [Geo Code]?

Madhivanan

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

vidhya
Posting Yak Master

108 Posts

Posted - 2008-07-16 : 07:38:46
real datatype
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-16 : 08:03:12
quote:
Originally posted by vidhya

real datatype


can we see the query used by you?it should work for real data.
Go to Top of Page

vidhya
Posting Yak Master

108 Posts

Posted - 2008-07-16 : 08:22:03
select round([Geo Code],0), [Bell Rating],[Boatyard Rating], Sunset from rpm_Acc where MarinaNo = 2780
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-16 : 08:28:28
try this too:-
cast([Geo Code] as int)
Go to Top of Page

vidhya
Posting Yak Master

108 Posts

Posted - 2008-07-16 : 08:40:10
thanks a lot its working fine.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-07-16 : 08:42:37
Depending on how you want to round values, and how the cast handles this, you may want to add or subtract .5 from your value when casting.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-07-16 : 08:42:57
note... casting it as an INT is not the same as the round() function. 40.9 would come out as 40 rather than 41. is that really what you want?

Em
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-07-16 : 09:40:25
quote:

note... casting it as an INT is not the same as the round() function. 40.9 would come out as 40 rather than 41. is that really what you want?



That's what I was referring to in my post ... The OP should review and test the rounding of the cast and compare that to what he or she wants, and then make an adjustment on the value when casting if necessary.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -