473,699 Members | 2,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Should I use SQL data type money or decimal given .NET datatype is decimal?

We're designing the data model for a project. The app will be in .NET, the
database will be in SQL Server 2005.

I'm a little confused on type conversion between the two and which I should
choose.

I found this good comparison chart:
http://msdn2.microsoft.com/en-us/library/ms131092.aspx

But for monetary amounts, it looks like decimal is how .NET is going to
store the value. So then, should I go with decimal in the database for a
nice match? But then it looks like money would be a good choice.

How do I know which I should ideally choose?

It would be nice if all the types exactly matched up between the platforms.

Thanks,
Ron
Apr 14 '07 #1
4 3697
Please disregard this -thx
"Ronald S. Cook" <rc***@westinis .comwrote in message
news:%2******** *******@TK2MSFT NGP05.phx.gbl.. .
We're designing the data model for a project. The app will be in .NET,
the database will be in SQL Server 2005.

I'm a little confused on type conversion between the two and which I
should choose.

I found this good comparison chart:
http://msdn2.microsoft.com/en-us/library/ms131092.aspx

But for monetary amounts, it looks like decimal is how .NET is going to
store the value. So then, should I go with decimal in the database for a
nice match? But then it looks like money would be a good choice.

How do I know which I should ideally choose?

It would be nice if all the types exactly matched up between the
platforms.

Thanks,
Ron


Apr 14 '07 #2
Ronald,

Why disregard? Care to say what conclusions you came to?

Personally, I think that if you are going to store money values in the
database, then money is fine. However, if the table you are storing values
on is an intermediate table which will store values performed on money and
then have more calculations performed on those results, then you should use
decimal with a much larger scale.

For example, say you have a Product table, with a Price field which is
the price for the Product. This price should be Money.

Now, if you had an intermediate table, with an average of how much money
was spent per customer, then that field should be decimal, with a larger
scale. The reason for this is that if you use those averages as inputs into
calculations later, then you don't want a truncation of values before the
money values go into the calc.

But then again, maybe you do, it all depends on what the accuracy you
need. Personally, I like to have as many places as possible being stored
(given practical limitations) and used for my intermediary calcs and then
perform the final rounding when the results are presented back to the user.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Ronald S. Cook" <rc***@westinis .comwrote in message
news:Ox******** ******@TK2MSFTN GP04.phx.gbl...
Please disregard this -thx
"Ronald S. Cook" <rc***@westinis .comwrote in message
news:%2******** *******@TK2MSFT NGP05.phx.gbl.. .
>We're designing the data model for a project. The app will be in .NET,
the database will be in SQL Server 2005.

I'm a little confused on type conversion between the two and which I
should choose.

I found this good comparison chart:
http://msdn2.microsoft.com/en-us/library/ms131092.aspx

But for monetary amounts, it looks like decimal is how .NET is going to
store the value. So then, should I go with decimal in the database for a
nice match? But then it looks like money would be a good choice.

How do I know which I should ideally choose?

It would be nice if all the types exactly matched up between the
platforms.

Thanks,
Ron



Apr 14 '07 #3
On Sat, 14 Apr 2007 10:20:31 -0400, Nicholas Paldino [.NET/C# MVP] wrote:
Ronald,

Why disregard? Care to say what conclusions you came to?

Personally, I think that if you are going to store money values in the
database, then money is fine. However, if the table you are storing values
on is an intermediate table which will store values performed on money and
then have more calculations performed on those results, then you should use
decimal with a much larger scale.

For example, say you have a Product table, with a Price field which is
the price for the Product. This price should be Money.

Now, if you had an intermediate table, with an average of how much money
was spent per customer, then that field should be decimal, with a larger
scale. The reason for this is that if you use those averages as inputs into
calculations later, then you don't want a truncation of values before the
money values go into the calc.

But then again, maybe you do, it all depends on what the accuracy you
need. Personally, I like to have as many places as possible being stored
(given practical limitations) and used for my intermediary calcs and then
perform the final rounding when the results are presented back to the user.
I agree with you about the accuracy but what benefits can you derive seeing
as money only makes sense to 2-3 decimal points?

--
Bits.Bytes
http://bytes.thinkersroom.com
Apr 14 '07 #4
Rad,

If you are storing intermediate calculation values in a table which are
monetary values, then you might want that accuracy when using those
intermediary values in further calculations. It wouldn't be until the end
where you want to apply the rounding.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Rad [Visual C# MVP]" <no****@nospam. comwrote in message
news:1c******** ********@thinke rsroom.com...
On Sat, 14 Apr 2007 10:20:31 -0400, Nicholas Paldino [.NET/C# MVP] wrote:
>Ronald,

Why disregard? Care to say what conclusions you came to?

Personally, I think that if you are going to store money values in
the
database, then money is fine. However, if the table you are storing
values
on is an intermediate table which will store values performed on money
and
then have more calculations performed on those results, then you should
use
decimal with a much larger scale.

For example, say you have a Product table, with a Price field which
is
the price for the Product. This price should be Money.

Now, if you had an intermediate table, with an average of how much
money
was spent per customer, then that field should be decimal, with a larger
scale. The reason for this is that if you use those averages as inputs
into
calculations later, then you don't want a truncation of values before the
money values go into the calc.

But then again, maybe you do, it all depends on what the accuracy you
need. Personally, I like to have as many places as possible being stored
(given practical limitations) and used for my intermediary calcs and then
perform the final rounding when the results are presented back to the
user.

I agree with you about the accuracy but what benefits can you derive
seeing
as money only makes sense to 2-3 decimal points?

--
Bits.Bytes
http://bytes.thinkersroom.com

Apr 15 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
6143
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number. "Decimal Number" sometimes serves to distinguish Base 10 numbers, eg "15", from Base 2 numbers, Eg "1111". At other times "Decimal Number" serves to differentiate a number from an integer. For the rest of this post I shall only use either...
3
8635
by: James Foreman | last post by:
I'm using DB2 UDB 8.1.2 on Suse linux. Try this: CREATE TABLE testsums (cost_of_sale decimal(7,2), price decimal(9, 2)); INSERT INTO testsums VALUES (10000, 30000); SELECT cost_of_sale/price AS division1 FROM testsums; SELECT sum(cost_of_sale)/sum(price) AS division2 FROM testsums; The first select gives 0.333333333333333333333333 The second gives 0.
4
1697
by: BerkshireGuy | last post by:
Our IT department wants to place our Access 2000 tables on an SQL server due to the fact the tables are quite large. With that said, can we still use the Access queries or do we have to do everything via SQL views? I would think we could just create an ODBC connection to the tables on the SQL server and that is the only thing we would need to change. Is my understanding correct? Are there any pros/cons with using the Access queries or...
5
1624
by: Brian P. Hammer | last post by:
I have data from multiple SQL tables, some of the tables will only have one row, while others multiple rows. I load a bunch of data from the various tables and add them to a third party grid. With some of the rows, I perform calculations on some of the rows and all this is loaded into the grid as well. I am trying to figure out the best way to store all this data so that it is easier to work with and perform calculations as users edit the...
11
3430
by: mesut demir | last post by:
Hi All, When I create fields (in files) I need assign a data type like char, varchar, money etc. I have some questions about the data types when you create fields in a file. What is the difference between data type 'CHAR' and 'TEXT'? When do you use 'VAR' in your datatype word? e.g. VARCHAR ?
0
2502
by: Sam | last post by:
I am trying to use a Simple form with 3 fields from SQL NorthWind Database (Order Details Table with 3 Fields. - OrderId, ProductId and Unit Price). The Field Unit Price has a data type of 'Money Type'. All I want is to able to edit/view/insert 'UnitPrice' field with 2 decimal points instead of 4 decimal points. If I use: Bind("UnitPrice", "{0:c}") in Edit Template, I got: "Input string was not in a correct format...". Although this...
0
2952
by: Sam | last post by:
Folks.. I am trying to use a Simple form with 3 fields from SQL NorthWind Database (Order Details Table with 3 Fields. - OrderId, ProductId and Unit Price). The Field Unit Price has a data type of 'Money Type'. All I want is to able to edit/view/insert 'UnitPrice' field with 2 decimal points instead of 4 decimal points.
5
57735
by: Ronald S. Cook | last post by:
For money values, C# seems to have just DOUBLE as a type. SQL Server 2005 has data types DECIMAL, FLOAT, MONEY, and NUMERIC that seem to all be able to hold a money time. So, given I'll be storing money as a double in code, what datatype should I have in the database for when I pass the value. I.e. which of all the SQL types best matches up? Thanks,
3
3437
by: Stephan Diehl | last post by:
Hi lazyweb, I'm wondering, if there is a usable money data type for python available. A quick search in pypi and google didn't convey anything, even though the decimal data type seemed to be planned as a money data type originaly. Thanks for any pointers Stephan
0
8685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7743
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.