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

后端 未结 4 1387
清歌不尽
清歌不尽 2021-02-13 01:45

I have a VARBINARY(MAX) field in a database table which contains ~35k characters. This field is a converted word document which unfortunately no longer have access to.

T

4条回答
  •  时光说笑
    2021-02-13 01:58

    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.)

提交回复
热议问题