Skip to content
Advertisement

SQL Server datatypes nvarchar and varchar are incompatible error

I’ve inherited a C# app which I’ve converted to vb. I get one error which as far as I can see has nothing to do with the conversion.

I have a SQL statement which is….

SELECT   ResolverID AS ddlValue, ResolverTeam & ' | ' & ResolverPerson AS ddlText 
FROM     dbo.TblResolvers 
ORDER BY ResolverTeam, ResolverPerson;

When this runs I get the error:

The data types nvarchar and varchar are incompatible in the boolean AND operator.

In the table both ResolverTeam and ResolverPerson are specified as (nvarchar(255), null)

Why am I getting this error?

Advertisement

Answer

Try replacing the & for a +; by the looks of it, what you’re trying to do is to concatenate 2 columns. Something you do need to be careful about is that nvarchar is double the size of regular varchar, which means there are chars in nvarchar that are not in the varchar table.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement