How do you get back the full content of rows in SQL Server Management Studio?
If you use \"results to grid\" the data is encoded, so things like line breaks are lost
I cast it to XML
select @variable_with_long_text
as [processing-instruction(x)] FOR XML PATH
The processing-instruction
bit is there to stop it entitising characters such as <
to <
Just use the default "Results to grid, then right click on the grid results and select "Save results as..." CSV.
The full content will be saved in the file, even with line breaks. Some varchar(max) columns had content of about 3MB and it was saved OK, not truncated.
I had never had this problem before changing to SSMS17, so I write here now.
In SSMS 17: select the table, right-click and select "modify first # rows", filter as you need, then select the cell in the modifiable grid: it will appear blank for long contents, press CTRL-A, then CTRL-C, and then past wherever you want.
One of the DBA's at my company suggested a possible solution is to put the data in a temporary variable and then use the print function in a loop, like so:
DECLARE @contents varchar(MAX)
SET @contents = ''
SELECT @contents = @contents + Contents + CHAR(13)
FROM dbo.tFOO
WHERE someConition
DECLARE @tContents TABLE (id int IDENTITY, contents varchar(MAX))
WHILE @contents LIKE '%' + CHAR(13) + '%'
BEGIN
PRINT SUBSTRING(@contents, 0, CHARINDEX(CHAR(13), @contents))
SET @contents = SUBSTRING(@contents, CHARINDEX(CHAR(13), @contents)+1, LEN(@contents) - CHARINDEX(CHAR(13), @contents))
END
I develop an add-in for SSMS - "SSMSBoost" and have recently added "Copy cell contents 1:1" feature (accessible in context menue of Grid). It will return you all data from the cell without any modifications and without truncating.