문제

In the query below nvarchar(max) seems to truncate at 4000 characters. That seems contrary to the answer here which says "Since NVARCHAR uses 2 bytes per character, that's approx. 1 billion characters."

DECLARE @test NVARCHAR(MAX)
DECLARE @i INT
SET @i=0
set @test=cast('x' as nvarchar(max))

while(@i<6000)
begin
set @test= (@test+ cast('x' as nvarchar(max)))
set @i=@i+1

end

print @TEST--has only 4000 characters
도움이 되었습니까?

해결책

Sorry, just found out that this is a limitation of the message screen in Sql server management studio. The code below shows correct results

DECLARE @test NVARCHAR(MAX)
DECLARE @i INT
SET @i=0
set @test=cast('x' as nvarchar(max))

while(@i<6000)
begin
set @test= (@test+ cast('x' as nvarchar(max)))
set @i=@i+1

end

print len(@TEST)--6001
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top