Skip to content

Latest commit

 

History

History
68 lines (62 loc) · 2.17 KB

data-type-precedence-transact-sql.md

File metadata and controls

68 lines (62 loc) · 2.17 KB
title description author ms.author ms.reviewer ms.date ms.service ms.subservice ms.topic ms.custom helpviewer_keywords dev_langs monikerRange
Data type precedence (Transact-SQL)
Learn about data type precedence for Transact-SQL.
MikeRayMSFT
mikeray
randolphwest
10/25/2024
sql
t-sql
reference
build-2024
ignite-2024
precedence [SQL Server]
data types [SQL Server], converting
data types [SQL Server], precedence
converting data types [SQL Server], precedence
precedence [SQL Server], data types
TSQL
=azuresqldb-current || =azuresqldb-mi-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqledge-current || =azure-sqldw-latest || =fabric

Data type precedence (Transact-SQL)

[!INCLUDE sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw-fabricsqldb]

When an operator combines expressions of different data types, the data type with the lower precedence is first converted to the data type with the higher precedence. If the conversion isn't a supported implicit conversion, an error is returned. For an operator combining operand expressions having the same data type, the result of the operation has that data type.

[!INCLUDE ssNoVersion] uses the following precedence order for data types:

  1. user-defined data types (highest)
  2. json
  3. sql_variant
  4. xml
  5. datetimeoffset
  6. datetime2
  7. datetime
  8. smalldatetime
  9. date
  10. time
  11. float
  12. real
  13. decimal
  14. money
  15. smallmoney
  16. bigint
  17. int
  18. smallint
  19. tinyint
  20. bit
  21. ntext
  22. text
  23. image
  24. timestamp
  25. uniqueidentifier
  26. nvarchar, including nvarchar(max)
  27. nchar
  28. varchar, including varchar(max)
  29. char
  30. varbinary, including varbinary(max)
  31. binary (lowest)

Related content