|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
SqlDataType.Decimal rounds to zero !?Hi, I'm writing a module to insert records to the main accounts table in our
CRM database. I've noticed in testing that the tax percent, which is a decimal data type with length 5, default value (0), precision 9 and scale 6 always enters zero. I've noticed if I run the test T-SQL statement it always returns a value of 0.0 instead of 0.085. Any ideas on what I'm missing would be hugely appreciated, I'm sort of tearing my hair out here. Thanks, Andre declare @taxpercent decimal(5) set @taxpercent = 0.085000 select @taxpercent The length 0f 5 that you refer to is the numbers of bytes that SQL Server
uses to store the value in. From a logical point of view the variable, requiring precision 9 and scale 6 must be declared as: declare @taxpercent decimal(9,6) decimal(5) is the same as decimal(5,0) which is precision 5 and scale 0 and the result you are observing is completely correct. Show quote "Andre Ranieri" <AndreRani***@discussions.microsoft.com> wrote in message news:13BEC8F7-3248-46AC-88A4-4A5239868BC8@microsoft.com... > Hi, I'm writing a module to insert records to the main accounts table in > our > CRM database. I've noticed in testing that the tax percent, which is a > decimal data type with length 5, default value (0), precision 9 and scale > 6 > always enters zero. > > I've noticed if I run the test T-SQL statement it always returns a value > of > 0.0 instead of 0.085. > > Any ideas on what I'm missing would be hugely appreciated, I'm sort of > tearing my hair out here. > > Thanks, > > Andre > > declare @taxpercent decimal(5) > set @taxpercent = 0.085000 > select @taxpercent Stephany,
Thanks, you explanation made a lot of sense. I'd read this on BOL earlier but it hadn't clicked until I read your post. Andre Ranieri Show quote "Stephany Young" wrote: > The length 0f 5 that you refer to is the numbers of bytes that SQL Server > uses to store the value in. > > From a logical point of view the variable, requiring precision 9 and scale 6 > must be declared as: > > declare @taxpercent decimal(9,6) > > decimal(5) is the same as decimal(5,0) which is precision 5 and scale 0 and > the result you are observing is completely correct. > > > "Andre Ranieri" <AndreRani***@discussions.microsoft.com> wrote in message > news:13BEC8F7-3248-46AC-88A4-4A5239868BC8@microsoft.com... > > Hi, I'm writing a module to insert records to the main accounts table in > > our > > CRM database. I've noticed in testing that the tax percent, which is a > > decimal data type with length 5, default value (0), precision 9 and scale > > 6 > > always enters zero. > > > > I've noticed if I run the test T-SQL statement it always returns a value > > of > > 0.0 instead of 0.085. > > > > Any ideas on what I'm missing would be hugely appreciated, I'm sort of > > tearing my hair out here. > > > > Thanks, > > > > Andre > > > > declare @taxpercent decimal(5) > > set @taxpercent = 0.085000 > > select @taxpercent > > > |
|||||||||||||||||||||||