I’ve encountered that problem with a database I do not own: the designer decided to store e-mail addresses in text columns and now, if one wants to search a person by e-mail address, he cannot use the where clause

select * from users where emailAddress = 'john@doe.com'

because SQL Server will report

Msg 402, Level 16, State 1, Line 3
The data types text and varchar are incompatible in the equal to operator.

To be able to actually search by e-mail address, you have to use a statement like

select * from users where cast( emailAddress as nvarchar(100) ) = 'john@doe.com'
Advertisements