Showing posts with label datatype. Show all posts
Showing posts with label datatype. Show all posts
Sunday, March 11, 2012
Can the "money" datatype be constrained to two decimal places?
I have a column that is a "money" datatype, which returns a four decimal
place value. It is a bit of a hassle to format this for display. Is there
anyway to default this to two decimal places?No, the datatype cannot be changed.
Look at CAST and CONVERT and you will see that there is a style that you can
use with CONVERT to return the value with 2 decimal places. (Or you could
stop using money and use DECIMAL if that meets your need.)
Russell Fields
"Top Gun" <nfr@.nospam.com> wrote in message
news:OyqMHnk8DHA.2540@.TK2MSFTNGP11.phx.gbl...
> I have a column that is a "money" datatype, which returns a four decimal
> place value. It is a bit of a hassle to format this for display. Is there
> anyway to default this to two decimal places?
>|||No, change to decimal as Russell suggests... But the benefit of using money
is that the front-end application should be able to recognize and format the
data to 2 decimals using localization... Many folks need the 4 decimals for
increased accuracy, then round for display...
Wayne Snyder, MCDBA, SQL Server MVP
Computer Education Services Corporation (CESC), Charlotte, NC
www.computeredservices.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Top Gun" <nfr@.nospam.com> wrote in message
news:OyqMHnk8DHA.2540@.TK2MSFTNGP11.phx.gbl...
> I have a column that is a "money" datatype, which returns a four decimal
> place value. It is a bit of a hassle to format this for display. Is there
> anyway to default this to two decimal places?
>
place value. It is a bit of a hassle to format this for display. Is there
anyway to default this to two decimal places?No, the datatype cannot be changed.
Look at CAST and CONVERT and you will see that there is a style that you can
use with CONVERT to return the value with 2 decimal places. (Or you could
stop using money and use DECIMAL if that meets your need.)
Russell Fields
"Top Gun" <nfr@.nospam.com> wrote in message
news:OyqMHnk8DHA.2540@.TK2MSFTNGP11.phx.gbl...
> I have a column that is a "money" datatype, which returns a four decimal
> place value. It is a bit of a hassle to format this for display. Is there
> anyway to default this to two decimal places?
>|||No, change to decimal as Russell suggests... But the benefit of using money
is that the front-end application should be able to recognize and format the
data to 2 decimals using localization... Many folks need the 4 decimals for
increased accuracy, then round for display...
Wayne Snyder, MCDBA, SQL Server MVP
Computer Education Services Corporation (CESC), Charlotte, NC
www.computeredservices.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Top Gun" <nfr@.nospam.com> wrote in message
news:OyqMHnk8DHA.2540@.TK2MSFTNGP11.phx.gbl...
> I have a column that is a "money" datatype, which returns a four decimal
> place value. It is a bit of a hassle to format this for display. Is there
> anyway to default this to two decimal places?
>
Can the "money" datatype be constrained to two decimal places?
I have a column that is a "money" datatype, which returns a four decimal
place value. It is a bit of a hassle to format this for display. Is there
anyway to default this to two decimal places?No, the datatype cannot be changed.
Look at CAST and CONVERT and you will see that there is a style that you can
use with CONVERT to return the value with 2 decimal places. (Or you could
stop using money and use DECIMAL if that meets your need.)
Russell Fields
"Top Gun" <nfr@.nospam.com> wrote in message
news:OyqMHnk8DHA.2540@.TK2MSFTNGP11.phx.gbl...
> I have a column that is a "money" datatype, which returns a four decimal
> place value. It is a bit of a hassle to format this for display. Is there
> anyway to default this to two decimal places?
>|||No, change to decimal as Russell suggests... But the benefit of using money
is that the front-end application should be able to recognize and format the
data to 2 decimals using localization... Many folks need the 4 decimals for
increased accuracy, then round for display...
--
Wayne Snyder, MCDBA, SQL Server MVP
Computer Education Services Corporation (CESC), Charlotte, NC
www.computeredservices.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Top Gun" <nfr@.nospam.com> wrote in message
news:OyqMHnk8DHA.2540@.TK2MSFTNGP11.phx.gbl...
> I have a column that is a "money" datatype, which returns a four decimal
> place value. It is a bit of a hassle to format this for display. Is there
> anyway to default this to two decimal places?
>
place value. It is a bit of a hassle to format this for display. Is there
anyway to default this to two decimal places?No, the datatype cannot be changed.
Look at CAST and CONVERT and you will see that there is a style that you can
use with CONVERT to return the value with 2 decimal places. (Or you could
stop using money and use DECIMAL if that meets your need.)
Russell Fields
"Top Gun" <nfr@.nospam.com> wrote in message
news:OyqMHnk8DHA.2540@.TK2MSFTNGP11.phx.gbl...
> I have a column that is a "money" datatype, which returns a four decimal
> place value. It is a bit of a hassle to format this for display. Is there
> anyway to default this to two decimal places?
>|||No, change to decimal as Russell suggests... But the benefit of using money
is that the front-end application should be able to recognize and format the
data to 2 decimals using localization... Many folks need the 4 decimals for
increased accuracy, then round for display...
--
Wayne Snyder, MCDBA, SQL Server MVP
Computer Education Services Corporation (CESC), Charlotte, NC
www.computeredservices.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Top Gun" <nfr@.nospam.com> wrote in message
news:OyqMHnk8DHA.2540@.TK2MSFTNGP11.phx.gbl...
> I have a column that is a "money" datatype, which returns a four decimal
> place value. It is a bit of a hassle to format this for display. Is there
> anyway to default this to two decimal places?
>
Friday, February 24, 2012
Can someone explain the precision of an integer in a sql db pls
Hi I am in the process of creating a new db in sql. In my users table I wish to set the UserIds as Integer datatype. It defualts on precision 4. Does this mean that when the column auto increments as its my primary key with a seed of one, my highest number allowed in the table would be row 9999. ?
Also if you where to store a phone number in your db, what column type would you give it. I have used varChar but its all numbers i want to store. Would this suffice.
ThanksHi,
That's four bytes, not four number places. So the range is from -2^31 (-2,147,483,648) through 2^31 - 1 (2,147,483,647). That's a lot of users... :-D
I usually store phone numbers as varchars, whether I include formatting symbols--(, ), -, whatever--or not. That way you don't have to worry about trailing zeroes (or leading ones if you also are using international phone numbers), and formatting for the user interface is way easier. In fact, if you are storing international phone numbers, you probably want to include the symbols as well.
Don
Subscribe to:
Posts (Atom)