Thursday, October 6, 2011

SQL Server 2008 R2 : T-SQL Data Type Precedence

When an operator combines two different data types, the data type precedence rules says that the data type with lowest precedence converts to the data type with highest precedence.  If the conversion is not supported implicit conversion, an error is returned. If both the operands are of same data type, then the result is of same data type.

SQL Server uses the following order of data type precedence.

1. User defined data types (highest)
2. sql_variant
3. xml
4. datatimeoffset
5. datetime2
6. datetime
7. smalldatetime
8. date
9. time
10. float
11. real
12. decimal
14. money
15. small money
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)

For complete details refer to the msdn link below:
 http://msdn.microsoft.com/en-us/library/ms190309.aspx 

Reference: DP (http://dptechnicalblog.blogspot.com/ )

No comments:

Post a Comment