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.
This field is present in my dev database and I'm looking to port this value to a live database. However, if I purely select the contents out of the grid results in SQL I seem only to get ~28k of the available characters.
So my question is this, what's the best way to migrate a field which has contents too large to simple copy and paste into and insert script?
Any thoughts greatly appreciated.
EDIT:
As additional info, outputting the results to file (albeit to .txt) seem to give me less chars than via grid. If I export the query results to file post running the query to grid I seem to get a literal representation of what's in the query window at the time (so if I stretch the window I get more characters than if I compress the column width)
varbinary [ ( n | max ) ] n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of the data entered + 2 bytes.
VARBINARY: A variable-width string up to a length of max-length bytes, where the maximum number of bytes is declared as an optional specifier to the type. The default is the default attribute size, which is 80, and the maximum length is 65000 bytes. VARBINARY values are not extended to the full width of the column.
In SQL, binary data types are used to store any kind of binary data like images, word files, text files, etc. in the table. In binary data types, we have an option like allowing users to store fixed-length or variable length of bytes based on requirements.
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:
SSMSBoost add-in for SSMS that I develop has 2 features that can help you:
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With