how to get the full resultset from SSMS

后端 未结 5 1447
南笙
南笙 2020-12-04 22:29

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

相关标签:
5条回答
  • 2020-12-04 23:02

    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 &lt;

    0 讨论(0)
  • 2020-12-04 23:10

    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.

    0 讨论(0)
  • 2020-12-04 23:14

    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.

    0 讨论(0)
  • 2020-12-04 23:20

    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
    
    0 讨论(0)
  • 2020-12-04 23:27

    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.

    0 讨论(0)
提交回复
热议问题