It's Geon coming in at the eleventh hour to drop a post before the month is up.
Today we are going to look at the following error(s):
Msg 402, Level 16, State 1, Line <number>
The data types ntext and varchar are incompatible in the equal to operator.
OR
Msg 306, Level 16, State 2, Line <number>
The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.
Fig. 1: #ntextProblems |
As the text is basically saying, these errors occur when you try to use an equal operator ("=") to compare a varchar value to a ntext value.
So what can you use to compare? The answer is right in the second error. You can use a LIKE.
See the example below:
...WHERE ntextValue LIKE 'SomeTextValue'...
Simple enough. :-)
DISCLAIMER: As stated, I’m not an expert so please, PLEASE feel free to politely correct or comment as you see fit. Your feedback is always welcomed. :-)