Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying large data from result of query in MS SQL Server Management Studio

I have a query that returns a large 'ntext' result. I want to copy this over to a plain text editor (Notepad), but only a part gets copied over.

I tried increasing Query Options -> Results -> Text, but the max seems 8192, which is insufficient for me.

Any ideas on how this can be achieved?

I'm using SQL Server Management Studio 2008, if that matters.

TIA! Raj

like image 941
ragebiswas Avatar asked Apr 21 '10 09:04

ragebiswas


2 Answers

The way I could get the entire data was using the option "Save Results as..." and then select TXT file, and then you can open it with a good editor like notepad++ , and you will have all the data.

Cheers =0)

like image 153
Chris Rosete Avatar answered Nov 13 '22 19:11

Chris Rosete


try something like this:

--creates file on server
declare @cmd varchar(1000)
select @cmd = 'osql -U -P -S -Q"select * from yourtable" -o"c:\yourtextfile.txt" -w50000'
exec master..xp_cmdshell @cmd

or

--creates file on server
master..xp_cmdshell 'bcp your_table_or_view out c:\file.bcp -S -U -P -c '

or

--the limit of 8192 is per column, so split your column into multiple columns
--you will get a 1 character gap between these "columns" though
;WITH YourQuery AS
(
    SELECT
        col1
        FROM ...
)
SELECT SUBSTRING(col1,1,8192), SUBSTRING(col1,8193,8192), SUBSTRING(col1,16385,8192) --...
like image 30
KM. Avatar answered Nov 13 '22 20:11

KM.