Thursday, March 22, 2007

Export SQL query results with BCP


Following command exports query results with the bcp into the specified text file. It could be used to get, for example, NTEXT fields that are longer than 4000 and cutted out in SQL query analyzer:
>>bcp "select * from MyTable" queryout C:\result.txt -c -S SERVERNAME -U USERNAME -P PASSWORD

4 comments:

Anonymous said...

Thanks... Works perfect

Alex Pinsker said...

You're mostly welcome :)

Anonymous said...

Thank you, I appreciate the kind of 'giveback to the INTERNET' that you people u do.

keep going.

Anonymous said...

I created a xml file using bcp query queryout file method but when i access the file from aXMLtextreader in .net it returns "DATA at the root level is invalid.Line 1, Position 1"
can you help