Question

The environment is SQL Server 2012. I'm about to change a clr procedure returned result column from varchar to nvarchar, but I'm not sure if the characters which can be found in varchar code page will always convert to the same character in unicode and also the other way. The bad example would be if someone would get the results from procedure with column of nvarchar and put that in database with varchar column. The question is, will they convert correctly always?

Was it helpful?

Solution

VARCHAR is specific to your system codepage. NVARCHAR holds Unicode characters. Unicode is always going to be a superset of any legacy codepage. As such, you can expect your conversions from VARCHAR -> NVARCHAR to map properly. However, if your NVARCHAR string later contains Unicode characters that are not found in your legacy codepage, the characters will be lost when converting back to VARCHAR.

When possible, you should avoid this type of conversion. Update the table column to NVARCHAR.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top