• Aleksandr Furman (5/27/2008)


    About size of nvarchar(max)

    I tried this:

    declare @C nvarchar(max)

    set @C = N'hello' + replicate('-',8000)

    print len(@c)

    the result was still 4000. Can someone explain why it wasn't more since nvarchar(max) can accept more then 4000

    The REPLICATE('-', 8000) has an implicit cast to NVARCHAR, try this to explicitly CAST it to NVARCHAR(MAX):

    declare @C nvarchar(max)

    set @C = N'hello' + CAST(replicate('-',8000) AS NVARCHAR(MAX))

    print len(@c)

    you get 8005 as the length.