Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put N Unicode before variable in SQL Server?

We usually use N for unicode string literals like this:

Select * 
From Customer 
Where Name = N'កខគ' --Unicode

Now I want to change it to be like this:

Declare @a varchar(Max)

Select * 
From Customer 
Where Name = N''+@a

At the second SQL statement it doesn't work at all. Any ideas? Thank you in advance.

like image 498
Bun Avatar asked Mar 18 '26 03:03

Bun


1 Answers

The N is only used as a prefix to coerce unicode literals. If your @a variable is already one of the unicode types (e.g. NVARCHAR) then it's not necessary to convert or coerce it in any way.

like image 79
rory.ap Avatar answered Mar 20 '26 18:03

rory.ap



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!