Skip to content

Instantly share code, notes, and snippets.

@pascalberger
Last active July 3, 2017 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pascalberger/3607bbb7c9dd94431f85a31b892fd3e0 to your computer and use it in GitHub Desktop.
Save pascalberger/3607bbb7c9dd94431f85a31b892fd3e0 to your computer and use it in GitHub Desktop.
SQL Server Double.MaxValue default value issue
-- It is not possible to use .NET Double.MaxValue=1.7976931348623157E+308 as default value for a float field.
-- Error: The floating point value '1.797693134862316e+308' is out of the range of computer representation (8 bytes).
-- CREATE TABLE FloatDefaultReproduction (FieldInt integer, FieldFloat float DEFAULT (1.7976931348623157E+308));
-- Same error if max value representation as returned by SQL Server is used.
-- Error: The floating point value '1.79769313486232E+308' is out of the range of computer representation (8 bytes).
-- CREATE TABLE FloatDefaultReproduction (FieldInt integer, FieldFloat float DEFAULT (1.79769313486232E+308));
-- Workaround 1:
-- CREATE TABLE FloatDefaultReproduction (FieldInt integer, FieldFloat float DEFAULT ((CONVERT(float,'1.7976931348623157E+308'))));
-- Workaround 2:
--CREATE TABLE FloatDefaultReproduction (FieldInt integer, FieldFloat float DEFAULT ((1.0E+308+7.976931348623157E+307)));
-- Statement throwing error
INSERT FloatDefaultReproduction
(FieldInt)
VALUES
(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment