Copying a large field (varbinary(max)) to file / clipboard

戏子无情 提交于 2019-12-04 00:04:07

To reliably copy large strings out of your SSMS query results pane, you want to pay close attention to the following settings (I'm looking at SSMS 10.50.2500.0 right now):

Tools > Options > Query Results > SQL Server > Results to Grid
    Max chars retreived:
        Non-XML: 65535
        XML: Unlimited

Tools > Options > Query Results > SQL Server > Results to Text
    Max chars displayed:    
        8192

You may need to at least open a new query window for the settings to apply. Notice that since XML is unlimited, you can potentially cast to XML to get full results. In this case you might do the following:

select cast(convert(varchar(max), MyColumn, 1) as xml) -- Use style 1 to get "0x..."

All that said, there may be better (and automatable/reproducible) methods for moving data around your systems as others have mentioned:

  • Setup a linked server to simply run an insert statement
  • Use openrowset to query a remote server
  • SSMS: Export data, Generate scripts, results to file
  • SSIS
  • 3rd party tools (Redgate Data Compare, etc.)

You can simply export (Save As) your results to a csv.

1) Run the query in SSMS
2) Results are display in the grid format
3) Right click on the grid, and choose Save Results As
4) Choose a format of csv or text file
5) Save the results to file

This way will export all the data and from there you can select all the text you want.

Note: These steps were done using SSMS 2012 but should be the same or similar for 2008 and other Database management tools

SSMSBoost add-in for SSMS that I develop has 2 features that can help you:

  1. It can "visualize" documents saved in cells right from ResultsGrid. So you will be able to see your document in word right from SSMS. Link: http://www.ssmsboost.com/Features/ssms-add-in-results-grid-visualizers-feature

  2. It can copy all bytes from cell to clipboard. You can paste the data then in some "good" text editor and save it as .doc. But first solution is better, as far as you will get word document directly: http://www.ssmsboost.com/Features/ssms-add-in-copy-results-grid-cell-contents-line-with-breaks

Skip the grid
In SSMS Query Results To File
Run the query

Or why don't you used linked server to insert directly

I tested and save to file does truncate.

Can you use .NET with a DataReader and .GetBinary ?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!