Thursday, January 7, 2010

union for different data types in T-SQL

Question:

What happens with this code?

select 'B'

union

select 4

Answer: The varchar is converted in int (error results)

Explanation: This is an example of an implicit conversion in T-SQL. In this case, an error is returned as the varchar is converted to an int, or an attempt is made, which returns an error. The int is of higher precedence than a varchar, so that is the order of conversions.

Note: The question of day is taken from SqlServerCentral.com. I want to compile selected QOD to share.

0 comments:

Post a Comment

Express your views about this post