snippetsqlMinor
How to store very small values (E-314) in SQL Server database?
Viewed 0 times
how314sqlserverstoredatabasesmallveryvalues
Problem
I had created table which hold small floating values using below query
But when it gives warning message for very small values (e-314)
Data gets inserted with value
How I can store & retirve very small values (E-314) in SQL Server database?
Thanks
create table temp_data (val float)But when it gives warning message for very small values (e-314)
insert into temp_pce_rank_data values(2.466987305926227e-314)Data gets inserted with value
'0' warning message is: The floating point value '2.466987305926227e-314' is out of the range of computer representation (8 bytes).How I can store & retirve very small values (E-314) in SQL Server database?
Thanks
Solution
None of the provided numeric types (
I see two options, if you want to store such numbers:
-
Use a custom solution with two columns, one for the mantissa and another for the exponent. The disadvantage will be that you'll have to do all the math operators and functions with complex expressions (even for addition).
-
Use a custom CLR User-Defined Type. From that page:
Beginning with SQL Server 2005, you can use user-defined types (UDTs) to extend the scalar type system of the server, enabling storage of CLR objects in a SQL Server database. UDTs can contain multiple elements and can have behaviors, differentiating them from the traditional alias data types which consist of a single SQL Server system data type.
Because UDTs are accessed by the system as a whole, their use for complex data types may negatively impact performance. Complex data is generally best modeled using traditional rows and tables. UDTs in SQL Server are well suited to the following:
Date, time, currency, and extended numeric types
Geospatial applications
Encoded or encrypted data
float, decimal) are able to store so small numbers. The example you have, 2.466987305926227e-314, is smaller than the smallest normal double-precision float number.I see two options, if you want to store such numbers:
-
Use a custom solution with two columns, one for the mantissa and another for the exponent. The disadvantage will be that you'll have to do all the math operators and functions with complex expressions (even for addition).
-
Use a custom CLR User-Defined Type. From that page:
Beginning with SQL Server 2005, you can use user-defined types (UDTs) to extend the scalar type system of the server, enabling storage of CLR objects in a SQL Server database. UDTs can contain multiple elements and can have behaviors, differentiating them from the traditional alias data types which consist of a single SQL Server system data type.
Because UDTs are accessed by the system as a whole, their use for complex data types may negatively impact performance. Complex data is generally best modeled using traditional rows and tables. UDTs in SQL Server are well suited to the following:
Date, time, currency, and extended numeric types
Geospatial applications
Encoded or encrypted data
Context
StackExchange Database Administrators Q#152171, answer score: 7
Revisions (0)
No revisions yet.