TSQL - make the literal value of a float

I understand a lot of problems when comparing floats and complain about their use in this case - but I am not the author of the table and have only a small obstacle to climb ...

Someone decided to use floats as you would expect a GUID to be used. I need to get all records with a specific float value.

sp_help MyTable

-- Column_name  Type    Computed    Length  Prec
-- RandomGrouping   float   no  8   53   

Here is my naive attempt:

--yields no results
SELECT RandomGrouping
FROM MyTable
WHERE RandomGrouping = 0.867153569942739

And here is a roughly working attempt:

--yields 2 records
SELECT RandomGrouping
FROM MyTable
WHERE RandomGrouping BETWEEN 0.867153569942739 - 0.00000001
      AND 0.867153569942739 + 0.00000001

--  0.867153569942739
--  0.867153569942739

In my naive attempt, is this a literal floating point literal? Or is it really a decimal literal that will be converted later?

If my literal is not a floating point literal, what is the syntax for creating a floating point literal?

: ... , , . , , . , , .


EDIT: DVK.

TSQL - MSSQLServer SQL.

script , float:

DECLARE @X float
SELECT top 1 @X = RandomGrouping
FROM MyTable
WHERE RandomGrouping BETWEEN 0.839110948199148 - 0.000000000001
  AND 0.839110948199148 + 0.000000000001
  --yields two records
SELECT *
FROM MyTable
WHERE RandomGrouping = @X

"", . , .

, () . . .


Zinglon:

, , .

DECLARE @Y binary(8)
SET @Y = 0x3FEAD9FF34076378

SELECT *
FROM MyTable
WHERE convert(binary(8), RandomGrouping) = @Y
+3
2

, . , , . SSMS script.

create table flt ( f float not null primary key )
insert into flt
select 0.111111111111111
union all
select 0.1111111111111111
select f, cast(f as binary(8)) from flt

, , (8) , :

select f from flt
where cast(f as binary(8)) = 0x3FBC71C71C71C71C
+1

, .

, float Sybase ( ) , 4.00000000000000000000... 3.99999999999999999999...... , .

- "" ( ).

" " ?

, , ( , ) MySQL

http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html

0

Source: https://habr.com/ru/post/1749625/


All Articles