What is the "select 123.866" data type in SQL Server 2005?

If I just write something like

select 10.00; 

What type does this give me?

A test was tested here to verify the binary representation of these types. The big surprise is that none of the drives matches the first line!

select cast(123.866 as binary) union all 
select cast(cast(123.866 as real) as binary) union all 
select cast(cast(123.866 as float) as binary) union all 
select cast(cast(123.866 as decimal) as binary) union all 
select cast(cast(123.866 as numeric) as binary) union all 
select cast(cast(123.866 as money) as binary) union all 
select cast(cast(123.866 as smallmoney) as binary)

--------------
0x0000000000000000000000000000000000000000000006030001DAE30100
0x000000000000000000000000000000000000000000000000000042F7BB64
0x00000000000000000000000000000000000000000000405EF76C8B439581
0x00000000000000000000000000000000000000000000120000017C000000
0x00000000000000000000000000000000000000000000120000017C000000
0x00000000000000000000000000000000000000000000000000000012E684
0x00000000000000000000000000000000000000000000000000000012E684

Can anyone explain this?


Initially, all I wanted to do was to avoid having to write a cast statement, assuming 123.866 is implicitly decimal. So I decided to check if these two statements were the same:

select cast(123.866 as decimal) 
select 123.866 
+3
source share
4 answers

(6,3) - , , . , tpe - 6 , 3 .

+6

@David M , , : : typeof SQL sql_variant_property:

select
    CAST(SQL_VARIANT_PROPERTY(123.866, 'BaseType') AS VARCHAR(20)) AS Type,
    CAST(SQL_VARIANT_PROPERTY(123.866, 'Precision') AS INT) AS Precision,
    CAST(SQL_VARIANT_PROPERTY(123.866, 'Scale') AS INT) AS Scale

:

Type     Precision  Type
numeric  6          3

, SQL Server 2008, 2005 . , 2005 .

numeric : (Transact SQL) : (Transact-SQL).

+8

. , ?

SQL Server

This article also shows what happens when you combine different types of data.

+1
source

Are you sure you need to send it to your request? When you select a result, what will be in the queue to process it? If this is an application, correctly identify the code and enter the type (if necessary). If this is a different request, you can pass it on without any problems.

0
source

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


All Articles