January 6, 2020 at 10:45 am
Hello, beginner in Tsql
I need help: here in one of the tables that I use, one of the fields is declared in decimal (10.5).
I understand that the field is therefore decimal but what are the 10 and 5 used for ??
Thanks for your help
January 6, 2020 at 11:23 am
Have you read the documentation, and was there anything in particular you didn't understand?
John
January 6, 2020 at 12:37 pm
Also, it's not decimal (10.5)
it's decimal(10,5)
, you need a comma(,
) between the precision and scale.
The document that John linked to should tell you all you need, but if there are any parts you don't understand do reply, and quote the bits you're not sure on.
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
January 6, 2020 at 12:38 pm
for a definition of decimal(10,5):
10 = maximum number of digits.
5 = number of digits to the right of the decimal point.
that means the largest value allowed before an error would be 99999.99999
so less than 100K. you have to take into consideration what the max value for a column might be when you create the field, as well as when you add fields together for SUM() functions and stuff like that.
Lowell
January 6, 2020 at 12:50 pm
so less than 100K. you have to take into consideration what the max value for a column might be when you create the field, as well as when you add fields together for SUM() functions and stuff like that.
Worth nothing that when using SUM
, the precision returned will always be 38. This means that truncation/overflow problems are only likely to occur if the scale has a value close to 38, and the values therefore exceed the maximum precision. Summing the values 99999.99999
and 1
won't generate an overflow error with SUM
, for example:
SELECT SUM(I)
FROM (VALUES (CONVERT(decimal(10, 5), 99999.99999)),
(1)) V(I);
SELECT system_type_name
FROM sys.dm_exec_describe_first_result_set(N'SELECT SUM(I) FROM (VALUES(CONVERT(decimal(10,5),99999.99999)),(1))V(I);', NULL, NULL);
So, if you are going to be aggregating, it's normally the scale you need to be aware of, rather than the precision.
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
January 6, 2020 at 3:16 pm
Hello, beginner in Tsql
I need help: here in one of the tables that I use, one of the fields is declared in decimal (10.5).
I understand that the field is therefore decimal but what are the 10 and 5 used for ??
Thanks for your help
Ummm... according to your previous posts, you've been working with SQL Server for at least 1 year and 7 months.ย Hardly the newbie you claim to be. ๐
In SQL Server, there are two places where "Help" might be stored for use with SSMS... locally (my personal preference) and online (really bad if you frequently work on the server itself but OK for local instances).
To get to either, just press the {F1} key.
If things weren't done quite right during the installation of SQL Server, even that might not work so there's always a web search.ย In this case, you'd want to search for "sql server decimal data type".
--Jeff Moden
Change is inevitable... Change for the better is not.
January 7, 2020 at 9:07 am
Jeff -itย needed to be said, but we are f1 AND web search rolled into one......
have you been hanging out with Joe again ? or are you not taking your medication? ๐ start shouting about cursors again!!!!
(ps - mail me the spare meds, I might need them)
MVDBA
January 7, 2020 at 11:57 pm
Jeff -itย needed to be said, but we are f1 AND web search rolled into one......
Heh... I guess that's true in a lot of cases.ย You would think that someone that has been working with SQL Server for 19 months would know one or the other, though.
have you been hanging out with Joe again ? or are you not taking your medication? ๐ start shouting about cursors again!!!!
(ps - mail me the spare meds, I might need them)
Lordy, I hope I didn't come across that way.ย I didn't slam them about Cobol, Punched Cards, Roman Numerals, not knowing ISO standards that no one can afford to buy, question their humanity for not posting code, nor question his position in life just because he didn't know something.
As for the meds... they're mine, I tell you... ALL MINE!ย ๐
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply