Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 349
Mych Avatar asked Dec 27 '12 13:12

Mych


People also ask

Can you compare varchar and nvarchar?

The key difference between varchar and nvarchar is the way they are stored, varchar is stored as regular 8-bit data(1 byte per character) and nvarchar stores data at 2 bytes per character. Due to this reason, nvarchar can hold upto 4000 characters and it takes double the space as SQL varchar.

Can nvarchar be converted to varchar?

Solution. Use Virtual View to load the data to Data Vault, and in Virtual View, use the CONVERT() function of SQL Server to extract NVARCHAR(MAX) data as VARCHAR.

What special characters are allowed in nvarchar?

If you use nchar / nvarchar then it's pretty much any character in any unicode set in the world.

What is the datatype with nvarchar?

The NVARCHAR data type stores strings of varying lengths. The string can include digits, symbols, and both single-byte and (in some locales) multibyte characters. The main difference between VARCHAR and NVARCHAR data types is the collation order.


1 Answers

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.

like image 57
Leonardo Avatar answered Sep 21 '22 06:09

Leonardo