DECLARE @x varchar (ten);D eclare @y int;declare @z VARCHAR (10); SET @x = ' 1000 '; SET @y = ' 2000 '; SET @z = ' +3000 ';
-The first Kind
SELECT case when @x < @y Then ' true ' Else ' FALSE ' END as [x<y?] If case is @y < @z Then ' true ' else ' fals E ' End as [y<z?], case is @x < @z Then ' TRUE ' ELSE ' FALSE ' END as [x<z?]
Result is
X<y? Y<z? X<z?
Truetruefalse
The second Kind
SELECT case when @x < @y Then ' true ' Else ' FALSE ' END as [CAST (x) <y?] If case is @y < @z Then ' true ' else ' False ' end as [Y<cast (z)], case is @x < @z Then ' TRUE ' ELSE ' false ' end as [x<z?] and Case is CAST (@x As int) < CAST (@z as int) then ' TRUE ' ELSE ' FALSE ' END as [CAST (x) <cast (z)?]
Result is
CAST (x) <y? Y<cast (z)? X<z? CAST (x) <cast (z)?
Truetruefalsetrue
SQL Tech Insider-Comparison of 7 varchar types of numbers and numbers of type int +cast applicable