Tuesday, February 14, 2012

CSV export via BCP, spaces in database name >:(

Hello, I'm having trouble with an SQL database that has a space in it's name. What I want to do is extract the table "fileinfo" from the database "Vigilant Server" to a CSV file "FileInfo.CSV". Also, know that I am neither a programmer nor a DB admin, merely a general technician and a writer of DOS BAT files.

First I tried using OSQL:
OSQL -U xxx -P xxx -d "Vigilant Server" -Q "SELECT * FROM fileinfo" -o FileInfo.CSV
It works but is incredibly slow.

Then I heard about BCP, and tried this:
BCP "Vigilant Server..fileinfo" out FileInfo.CSV -U xxx -P xxx -c -t ,
No matter where I put the quotation marks, I can't get BCP to recognize Vigilant Server as the database name.

I am not doing something right? Is there another way to do this that's better suited to what I'm trying to do? Any help would be appreciated.Check out the books online (bol) for the bcp command:

To specify a database name that contains a space or quotation mark, you must use the q option.|||That worked just great, thank you for your help.|||You are welcome. The bol tool will be an invaluable resource for you.

No comments:

Post a Comment