Monday, August 10, 2009

ntext Database Type

The ntext database type is a unicode variable length data type in SQL server. SQL server profiler creates these fields if you save a profile to a trace table.

If we try to filter one of these trace tables like this,

select * from TraceTable where TextData like '%value%'

That is fine, but if we try to do this,

select * from TraceTable where TextData = 'value'

We get an error like this,

The data types ntext and varchar are incompatible in the equal to operator.

The solution is this,

select * from TraceTable where cast(textdata as varchar(100)) = 'value'

No comments: