Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to user prefix 'N' for unicode with nvarchar variable in SQL Server?

How to user prefix 'N' for unicode with nvarchar variable in SQL Server? For example:

Given this variable:

declare @Query1 nvarchar(max) 

I can assign to it like this:

set @Query1 = N'لاحظات'

But what if I want to use N@Query1 somewhere?

like image 204
Nijesh Patel Avatar asked May 14 '10 18:05

Nijesh Patel


1 Answers

You only need to use N'xyz' when you have literal text. Once the nvarchar data is in a variable or result set column of nvarchar data type you no longer need to use the N'...' notation, the system knows the data type at that point.

try it out:

DECLARE @A   nvarchar(100)
       ,@B   nvarchar(100)
SET @A = N'anything here!!'

SET @B=@A --would work the same if coming from a query result set as well

SELECT @B --will show special unicode characters
like image 101
KM. Avatar answered Nov 14 '22 21:11

KM.