• I experienced the same problem of printing nvarchar(max)/varchar(max), with truncation at 4000/8000 characters. I strongly agree: it's a bug (while Microsoft insists it's a feature). I found a very simple/effective workaround. I don't know how/why my workaround works, but it works, bullet-proof, all the times. Try it.

    After bulding a @LongString longer than 8000 chars, as varchar(max), create a small temp table with two fields, insert the long string @LongString you created through your code into the varchar(max) field, and then retrieve it from the table, as shown below:

    CREATE TABLE [dbo].[TEMP](

    [RecNo] [smallint] IDENTITY(1,1) NOT NULL,

    [LongString] [varchar](max) NULL

    ) ON [PRIMARY]

    INSERT INTO [dbo].[TEMP] ([LongString])

    SELECT @LongString

    SELECT LongString FROM [dbo].[TEMP] WHERE RecNo = 1

    --the above SELECT returns the entire unchopped string,

    --which you can copy and paste into a text editor for analysis

    DROP TABLE [dbo].[TEMP]

    That's all there is to it.

    Enjoy!

    Mike Vassalotti

    mvassal@hotmail.com

    Herndon, Virginia