tsql - In vs. Comparison Search Conditions -


i understand where 1 = '1' returns true, , where 222 = convert(varchar, 222) return true in t-sql.

but, when working in, can test_expression , subquery of different datatypes? example can test_expression int, , subquery varchar?

they can be: datatypes cast highest based on "datatype precedence" rules.

logically, x in (a,b,c) x=a or x=b or x=c of course. relevant contrived case using scalar values. really don't know if values cast float (the highest here) before comparison (..in..) or cast per comparison (..or..or..)

where   cast(1 int) in ('1', cast(1.0 float), 1.0 /*decimal*/) 

for subquery in in clause, column has data type cast per scalar rules

edit, after comment:

all datatypes implicitly cast

select top 1 * sys.columns     1 in (select cast('1' char(1)) sys.columns) 

or

declare @intvar int = 1, @charvar char(1) = '1';  select top 1 * sys.columns     @intvar in (select @charvar sys.columns) 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -