We have a SQL generator that emits SQL conditional statements generically for specified fields (which for the sake of discussion: we will label as myField
).
So, if myField
is of type NVARCHAR
, we can do a comparison of said field against a string like so: myField = 'foo'
. However, this does not work for fields of type NTEXT
. Thus, we have to do the comparison with a cast: CAST(myField as NVARCHAR(MAX)) = 'foo'
. This will in fact work if myField
is of type NVARCHAR
or NTEXT
.
This brings me to my question: what is the performance hit of doing the aforementioned cast on a field that is already of type NVARCHAR
? My hope is that SQL Server is smart enough to dynamically recognize that myField
is already of type NVARCHAR
(effectively turning the CAST into a NO-OP).
Thanks in advance.