• Shaun McGuile (2/2/2009)


    REPLICATE function is obviously broken then.

    Hi Shaun,

    No, it's not. It just adheres to the standard operating procedure of datatype in = datatype out.

    CREATE TABLE #t

    (ID int,

    LongName nvarchar(MAX));

    INSERT #t

    VALUES (1, REPLICATE(CAST(N'A' AS nvarchar(MAX)), 4000000));

    SELECT DATALENGTH(LongName) FROM #t WHERE ID = 1;

    Returns 8000000.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/