How to custom prefix "N" for unicode with nvarchar variable in SQL Server?

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

Given this variable:

declare @Query1 nvarchar(max) 

I can assign him the following:

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

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

+7
sql sql-server-2008
source share
4 answers

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

try:

 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 
+7
source share

It is used with string literals to indicate that text should be treated as unicode. eg

 DECLARE @something NVARCHAR(100) SET @something = N'sometext' 
0
source share
 Declare @var nvarchar(255) Set @var = N'Hello World' print @var create table #tmp( columnA nvarchar(255) not null) insert into #tmp(columnA) Values (N'Test') Select @var = columnA from #tmp print @var drop table #tmp 
0
source share
 declare @nv1 nvarchar(50) = N'لاحظات', @nv2 nvarchar(50) = 'لاحظات', @v varchar(50) = N'لاحظات' declare @nv3 nvarchar(50) = @nv1 + ' hallo', @nv4 nvarchar(50) = @nv1 + N' hallo' select @nv1, @nv2, @nv3, @nv4, @v 
0
source share

All Articles