SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Money Field Decimal Places
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

macca
Posting Yak Master

Ireland
104 Posts

Posted - 11/16/2007 :  10:51:27  Show Profile  Reply with Quote
I have a field in a database which is a datatype Money. When I run a select query the data is coming back with 4 decimal places like 100.0000 but I only want 2 decimal places like 100.00.

Anyone know how to get this?
macca

khtan
In (Som, Ni, Yak)

Singapore
13672 Posts

Posted - 11/16/2007 :  11:00:18  Show Profile  Send khtan a Yahoo! Message  Reply with Quote
1. don't use money data type. money is 4 decimal places
2. use convert() or cast() to convert to decimal data type with 2 decimal places.


KH
Time is always against us

Go to Top of Page

macca
Posting Yak Master

Ireland
104 Posts

Posted - 11/16/2007 :  11:10:16  Show Profile  Reply with Quote
how would you use CAsT or Convert to do this, can you give an example please.

Thanks,
macca
Go to Top of Page

jhocutt
Constraint Violating Yak Guru

USA
385 Posts

Posted - 11/16/2007 :  11:12:34  Show Profile  Visit jhocutt's Homepage  Send jhocutt an AOL message  Reply with Quote
create table #tmp (
c1 money
)

insert into #tmp values (1.1234)
select c1, cast(c1 as numeric(10,2)), convert(numeric(10,2), c1)
from #tmp


"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking

Edited by - jhocutt on 11/16/2007 11:13:41
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
13672 Posts

Posted - 11/16/2007 :  11:15:18  Show Profile  Send khtan a Yahoo! Message  Reply with Quote
quote:
Originally posted by macca

how would you use CAsT or Convert to do this, can you give an example please.

Thanks,
macca


read the BOL


KH
Time is always against us

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000 Version 3.4.03