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?
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.
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.
If you use nchar / nvarchar then it's pretty much any character in any unicode set in the world.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With