If you suspect that your varchar variable has a new line character , use the following to remove it -
REPLACE(REPLACE( @variable,CHAR(13),''),CHAR(10),'')
IIf
arises because it is a library function: unlike the C-derived conditional operator, both truepart and the falsepart will be evaluated regardless of which one is actually returned. Consider the following example:value = 10 result = IIf(value = 10, TrueFunction, FalseFunction)
IIf
will cause both TrueFunction and FalseFunction to be executed.a = 10 b = 0 result = IIf(b <> 0, a / b, 0)
a = 10
b = 0
_temp1 = a / b ' Error if b = 0
_temp2 = 0
_temp3 = b <> 0
result = IIf(_temp3, _temp1 , _temp2)
IIf
to an intrinsic function; had this happened, the compiler would have been able to perform type inference and short-circuiting by replacing the function call with inline code.